home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: 500 MB Amiga Software / 500 MB Amiga Software - Euber 130 - Amiga Games Disc & Mag.iso / userbox / publicdomain / muchmore46 / src / muchmore.mod next >
Text File  |  1995-03-12  |  94KB  |  2,844 lines

  1. (*---------------------------------------------------------------------------
  2. :Program.    MuchMore.mod
  3. :Author.     Fridtjof Siebert
  4. :Address.    Nobileweg 67, D-70439 Stuttgart, Germany
  5. :Shortcut.   [fbs]
  6. :Copyright.  Freeware
  7. :Language.   Oberon-2
  8. :Translator. Amiga Oberon Compiler v3.10
  9. :History.   V1.0 summer-88: First very slow internal version             [fbs]
  10. :History.   V1.1 24-Sep-88: First published version                      [fbs]
  11. :History.   V1.2 26-Nov-88: Now displays Filelength & Percentage         [fbs]
  12. :History.        27-Nov-88: Mouse can be used instead of Space/BackSpace [fbs]
  13. :History.   V1.3 29-Apr-89: Strong increase in speed, removed WarpText   [fbs]
  14. :History.        29-Apr-89: Now supports Numeric Keys (Home,PgUp etc.)   [fbs]
  15. :History.        29-Apr-89: Now opens Screen as big as gfx.normalDisplay [fbs]
  16. :History.   V1.4 29/30-Apr-89: Asynchronus loading/displaying. Very nice [fbs]
  17. :History.        30-Apr-89, 00:33: Removed bugs in Filelength & L-Command[fbs]
  18. :History.        30-Apr-89, 02:21: Added Find-Command                    [fbs]
  19. :History.        30-Apr-89, 10:30: Scrolling stops when window inactive  [fbs]
  20. :History.        01-May-89: Allocates no more unneeded memory for text   [fbs]
  21. :History.        07-May-89: Allocates even less memory now               [fbs]
  22. :History.        14-May-89: Removed deadlock-bug with Find-Window        [fbs]
  23. :History.   V1.5 25-May-89: Added print feature                          [fbs]
  24. :History.        25-May-89: Removed all imports (apart from Arts)        [fbs]
  25. :History.        26-May-89: inspired by J. Kupfer, I added nk 5 to quit  [fbs]
  26. :History.        26-May-89: Now handle BS correctly                      [fbs]
  27. :History.   V1.6 02-Jul-89: Now supports several fontstyles and colors   [fbs]
  28. :History.   V1.7 03-Jul-89: Is again as fast as it was with 2 colors     [fbs]
  29. :History.        03-Jul-89: Now no more crashes when quitting while print[fbs]
  30. :History.        07-Jul-89: removed bug with texts of length 0           [fbs]
  31. :History.   V1.8 10-Jul-89: small bug in find-command removed            [fbs]
  32. :History.        10-Jul-89: now found strings are highlighted            [fbs]
  33. :History.        14-Jul-89: nk0 to display fileinfo                      [fbs]
  34. :History.   V2.0 06-Aug-89: Ported this to OBERON                        [fbs]
  35. :History.        06-Aug-89: Added ARP-FileRequester                      [fbs]
  36. :History.        07-Aug-89: Added L - (load new file) Command            [fbs]
  37. :History.   V2.1 03-Sep-89: no more gurus if an r/w error occures        [fbs]
  38. :History.        03-Sep-89: MM used to execute CSI-Codes backwards. fixed[fbs]
  39. :History.        03-Sep-89: ping / pong with Shift+Fn / Fn               [fbs]
  40. :History.        03-Sep-89: new command: goto                            [fbs]
  41. :History.   V2.2 05-Sep-89: will run with any keymapping now             [fbs]
  42. :History.   V2.3 17-Sep-89: New command: sleep & Pop-Up feature          [fbs]
  43. :History.        17-Sep-89: "MuchMore -s" will go to sleep immediately   [fbs]
  44. :History.        17-Sep-89: Interprets <CSI>m as <CSI>0m now             [fbs]
  45. :History.   V2.4 17-Sep-89: New command: write block "w"                 [fbs]
  46. :History.        17-Sep-89: rewritten argument parser to allow quotes    [fbs]
  47. :History.   V2.5 18-Sep-89: now uses the 8x8 font set with SetFont       [fbs]
  48. :History.        19-Sep-89: no more scatters memory. Allocates 4K Chunks [fbs]
  49. :History.   V2.6 26-Jun-90: Made MuchMore reentrant                      [fbs]
  50. :History.        26-Jun-90: Opens 1-Plane Screen if memory is rare       [fbs]
  51. :History.        26-Jun-90: Asynchronus fast scrolling with Ctrl-Up/Down [fbs]
  52. :History.        26-Jun-90: Now supports interlaced screens              [fbs]
  53. :History.        08-Aug-90: CLI-Option '-l' to toggle interlaced mode    [fbs]
  54. :History.   V2.7 09-Aug-90: no more RethinkDisplay()s,looks good with 2.0[fbs]
  55. :History.        10-Aug-90: Supports Kick2.0 ASL-FileRequester           [fbs]
  56. :History.   V2.8 26-Dez-90: Leaves space between lines on interl. scrns  [fbs]
  57. :History.   V3.0 04-Jul-91: Supports any non-proportional font now       [fbs]
  58. :History.        04-Jul-91: no more supports '-s' (sleep),was rarely used[fbs]
  59. :History.        04-Jul-91: new Options -f<font> and -s<size> for font   [fbs]
  60. :History.        09-Nov-91: Find works w/ dmouse(window may get inactive)[fbs]
  61. :History.   V3.1 04-Sep-92: Uses Screenmode of Workbench screen          [fbs]
  62. :History.   V3.2 02-Nov-92: Supports non-scrollable screens              [fbs]
  63. :History.        02-Nov-92: Complete redraw doesn't scroll anymore       [fbs]
  64. :History. V3.2.1 24-Dec-92: XPK Support                             (C.Stiens)
  65. :History.        24-Dec-92: New option -p for Password              (C.Stiens)
  66. :History.        24-Dec-92: New option -e for Extra Spacing         (C.Stiens)
  67. :History.        24-Dec-92: New option -c for Screen Colors         (C.Stiens)
  68. :History.        24-Dec-92: Tooltypes                               (C.Stiens)
  69. :History. V3.2.2 08-Jan-93: Doesn't use MyMakeScreen() no more      (C.Stiens)
  70. :History. V3.2.3 08-Feb-93: Now closes Console Device               (C.Stiens)
  71. :History.        08-Feb-93: Non-Scroll Mode didn't work always      (C.Stiens)
  72. :History.        10-Feb-93: ScreenMode Requester                    (C.Stiens)
  73. :History.        10-Feb-93: New Option -s for Scroll Mode           (C.Stiens)
  74. :History.        10-Feb-93: Busy Pointer                            (C.Stiens)
  75. :History.        14-Feb-93: Now evals Tooltypes also on CLI start   (C.Stiens)
  76. :History. V3.2.4 15-Feb-93: Clears Idcmp while Busy                 (C.Stiens)
  77. :History.        15-Feb-93: Bugs in GetString fixed                 (C.Stiens)
  78. :History.        19-Feb-93: More Scrollmodes                        (C.Stiens)
  79. :History.        20-Feb-93: Bug in Type() fixed                     (C.Stiens)
  80. :History. V3.2.5 08-Mar-93: Asynch Scrolling changed                (C.Stiens)
  81. :History.        08-Mar-93: New Option -t for Taskpri               (C.Stiens)
  82. :History.        10-Mar-93: Now uses Dos.ReadArgs if KS 2.04        (C.Stiens)
  83. :History. V3.2.6 19-Mar-93: scrollmode 3 now also scrolls soft      (C.Stiens)
  84. :History.        19-Mar-93: New Option -o for one plane             (C.Stiens)
  85. :History.        19-Mar-93: New Option -a for tab width             (C.Stiens)
  86. :History.        19-Mar-93: Removed QText                           (C.Stiens)
  87. :History.        21-Mar-93: Opens screen with full overscan width   (C.Stiens)
  88. :History.        22-Mar-93: Filename can be on any pos at KS1.3     (C.Stiens)
  89. :History.        27-Mar-93: New Option N=NOOSCAN                    (C.Stiens)
  90. :History. V3.2.7 07-Apr-93: Dont pokes to bitmap no more            (C.Stiens)
  91. :History. V3.2.8 12-Apr-93: New Option B=PLANES                     (C.Stiens)
  92. :History. V3.2.9 12-May-93: Implemented V36 ANSI Codes              (C.Stiens)
  93. :History. 3.2.10 16-May-93: Locale Support                          (C.Stiens)
  94. :History.        16-May-93: DispMode-Requester font-sensitive       (C.Stiens)
  95. :History.   V3.3 21-Jun-93: Code optimised                          (C.Stiens)
  96. :History.        25-Jun-93: Safe quit                               (C.Stiens)
  97. :History.   V3.4 29-Jun-93: Clipboard support                       (C.Stiens)
  98. :History.        29-Jun-93: took version number out of catalog      (C.Stiens)
  99. :History.   V3.5 31-Jul-93: case sensitive search, Boyer-Moore Alg. (C.Stiens)
  100. :History.   V3.6 15-Aug-93: Page up/down with softscroll reimpl.    (C.Stiens)
  101. :History.        16-Aug-93: Flash at EOF/BOF                        (C.Stiens)
  102. :History.   V3.7 28-Oct-93: New option E=EDITOR                     (C.Stiens)
  103. :History.        21-Nov-93: MM was not 100% pure (BusyPointer)      (C.Stiens)
  104. :History.        21-Nov-93: Password has to be entered in stringgad (C.Stiens)
  105. :History.   V4.0 07-Dec-93: MM can run in a WB Window               (C.Stiens)
  106. :History.        07-Dec-93: Options WINDOW, LEFT, TOP, WIDTH, HEIGHT(C.Stiens)
  107. :History.        07-Dec-93: Kick 1.3 is no more supported           (C.Stiens)
  108. :History.        07-Dec-93: Removed Options SCROLLMODE and NOOSCAN  (C.Stiens)
  109. :History.   V4.1 05-Jan-94: Prefs BusyPointer, set rp.mask or MaxPen(C.Stiens)
  110. :History.        10-Jan-94: Pipe Support, new option PUBSCREEN      (C.Stiens)
  111. :History.        12-Jan-94: Option SCROLLMODE reintroduced          (C.Stiens)
  112. :History.        12-Jan-94: New Option I=INTERLEAVED                (C.Stiens)
  113. :History.   V4.2 29-Jan-94: Zoom Gadget (v39)                       (C.Stiens)
  114. :History.        29-Jan-94: Better test for Pipe                    (C.Stiens)
  115. :History.        30-Jan-94: Icon is found if MM is started w/path   (C.Stiens)
  116. :History.        31-Jan-94: New option FASTQUIT                     (C.Stiens)
  117. :History.        31-Jan-94: ShowTask allocates his signals now      (C.Stiens)
  118. :History.   V4.3 06-Mar-94: Change rp.mask only if necessary        (C.Stiens)
  119. :History.        16-Mar-94: New options: FRWIDTH, FRHEIGHT          (C.Stiens)
  120. :History.        20-Mar-94: Hide password when entering             (C.Stiens)
  121. :History.   V4.4 17-Jun-94: Bug in task sync fixed                  (C.Stiens)
  122. :History.        17-Jun-94: Uses ASL ScreenMode Requester now       (C.Stiens)
  123. :History.   V4.5 30-Jun-94: Bug w/ SetFont() fixed                  (C.Stiens)
  124. :History.   V4.6 18-Aug-94: Find command also with 's' key          (C.Stiens)
  125. :History.        09-Mar-95: Dont filters asciis 128-160 anymore     (C.Stiens)
  126. :Contents.   A Soft-Scrolling ASCII-File Viewer.
  127. :Remark.     Compile: 'Oberon -svbcrntzdma MuchMore' for short code
  128. :Remark.     Compile: 'Oberon -dma MuchMore' for safe code
  129. :Remark.     Link:    'OLink -dma MuchMore'
  130. ---------------------------------------------------------------------------*)
  131.  
  132. MODULE MuchMore; (* $StackChk- *)
  133.  
  134. IMPORT loc:= Locale,
  135.        ip := IFFParse,
  136.        u  := Utility,
  137.        con:= Console,
  138.        str:= Strings,
  139.        ie := InputEvent,
  140.        I  := Intuition,
  141.        g  := Graphics,
  142.        d  := Dos,
  143.        e  := Exec,
  144.        ol := OberonLib,
  145. (* $IF quiet *) NoRequesters, (* $END *)
  146.        SYS:= SYSTEM;
  147.  
  148.  
  149. CONST
  150.   MuchText = "MuchMore 4.6 © 1988-95 AMOK\o$VER: muchmore 4.6 (11.3.95)";
  151.   Version = "v4.6";
  152.  
  153.   MSGOOM        = 0;
  154.   MSGCOS        = 1;
  155.   MSGCOW        = 2;
  156.   MSGCOF        = 3;
  157.   MSGRWERR      = 4;
  158.   MSGRETRYABORT = 5;
  159.   MSGEMPTY      = 6;
  160.   MSGSAVE       = 7;
  161.   MSGUSE        = 8;
  162.   MSGCANCEL     = 9;
  163.   MSGOK         = 10;
  164.   MSGCHOOSESM   = 11;
  165.   MSGINFOFMT    = 12;
  166.   MSGH1         = 13;
  167.   MSGH2         = 14;
  168.   MSGH3         = 15;
  169.   MSGH4         = 16;
  170.   MSGH5         = 17;
  171.   MSGH6         = 18;
  172.   MSGH7         = 19;
  173.   MSGH8         = 20;
  174.   MSGH9         = 21;
  175.   MSGH10        = 22;
  176.   MSGH11        = 23;
  177.   MSGH12        = 24;
  178.   MSGH13        = 25;
  179.   MSGH14        = 26;
  180.   MSGH15        = 27;
  181.   MSGH16        = 28;
  182.   MSGH17        = 29;
  183.   MSGH18        = 30;
  184.   MSGH19        = 31;
  185.   MSGH20        = 32;
  186.   MSGH21        = 33;
  187.   MSGH22        = 34;
  188.   MSGH23        = 35;
  189.   MSGH24        = 36;
  190.  
  191.  
  192.   TYPE
  193.     MSGTYPE = ARRAY 37 OF e.LSTRPTR;
  194.  
  195.   CONST
  196.  
  197.     MSGS = MSGTYPE(
  198.       SYS.ADR( "Out of memory"      ),
  199.       SYS.ADR( "Can't open screen"  ),
  200.       SYS.ADR( "Can't open window"  ),
  201.       SYS.ADR( "Can't open file"    ),
  202.       SYS.ADR( "Read/Write Error"   ),
  203.       SYS.ADR( "Retry|Abort"        ),
  204.       SYS.ADR( "File empty"         ),
  205.       SYS.ADR( "Save"               ),
  206.       SYS.ADR( "Use"                ),
  207.       SYS.ADR( "Cancel"             ),
  208.       SYS.ADR( " OK "               ),
  209.       SYS.ADR( "Choose Screen Mode:"),
  210.       SYS.ADR( " File: %-30.30s %ld%% (%ld of %ld Bytes) %ld Lines"),
  211.       SYS.ADR( "\x13                \x15  MuchMore %s Commands:  "),
  212.       SYS.ADR( " \x0dSpace\x05,\x0d LMB\x05:         Start / Stop scrolling, Quit at end of file"),
  213.       SYS.ADR( " \x0dBackSpace\x05,\x0d RMB\x05:     Start / Stop scrolling backwards"),
  214.       SYS.ADR( " \x0dUp\x05/\x0dDown\x05:            Move one line \x0dup\x05 or \x0ddown\x05"),
  215.       SYS.ADR( " \x0dShift \x05+\x0d Up\x05/\x0dDn\x05:      Start / Stop quick scrolling \x0dup\x05 or \x0ddown\x05"),
  216.       SYS.ADR( " \x0dControl\x05:            Increase scroll speed"),
  217.       SYS.ADR( " \x0dAlt\x05+\x0dUp\x05/\x0dDn\x05,\x0d PgUp\x05/\x0dDn\x05: Move one page \x0dup\x05 or \x0ddown\x05"),
  218.       SYS.ADR( " \x0dT\x05,\x0d Home \x05/\x0d B\x05,\x0d End\x05:   Goto \x0dt\x05op / \x0db\x05ottom of text"),
  219.       SYS.ADR( " (\x0DShift\x05) \x0DF\x05, \x0DN\x05, \x0DP\x05:    \x0DF\x05ind string (case sensitive), \x0DN\x05ext, \x0DP\x05revious"),
  220.       SYS.ADR( " \x0dShift \x05+\x0d Fn\x05:         Set textmarker #n to current position"),
  221.       SYS.ADR( " \x0dFn\x05:                 Goto marker #n or set marker #n if it wasn't set yet"),
  222.       SYS.ADR( " \x0dG\x05:                  \x0dG\x05oto line..."),
  223.       SYS.ADR( " \x0dNK 0\x05:               Display info line"),
  224.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d O\x05:    Print text"),
  225.       SYS.ADR( " \x0dW\x05:                  \x0dW\x05rite block between marker #1 and #2 to file or prt"),
  226.       SYS.ADR( " \x0dL\x05:                  \x0dL\x05oad new text"),
  227.       SYS.ADR( " \x0dHELP\x05,\x0d H\x05:            Show commands"),
  228.       SYS.ADR( " \x0dESC\x05,\x0d Q\x05,\x0d X\x05,\x0d NK 5\x05:\x0d    Q\x05uit"),
  229.       SYS.ADR( "© \x131988-95 Fridtjof Siebert & Christian Stiens"),
  230.       SYS.ADR( ""),
  231.       SYS.ADR( "  \x13Please refer to MuchMore.doc for a detailed copyright notice"),
  232.       SYS.ADR( "  This is another product of the Amiga MODULA & OBERON Klub Stuttgart - \x0d\x13AMOK"),
  233.       SYS.ADR( " \x0dC\x05:                  \x0dC\x05opy block between marker #1 and #2 to clipboard"),
  234.       SYS.ADR( " \x0dShift \x05+\x0d Alt \x05+\x0d E\x05:    \x0dE\x05dit text") );
  235.  
  236.  
  237.  
  238. TYPE BusyPointer = ARRAY 36 OF INTEGER;
  239.  
  240. CONST TheBusyPointer = BusyPointer(
  241.   00000U,00000U,
  242.   00400U,007C0U, 00000U,007C0U, 00100U,00380U, 00000U,007E0U,
  243.   007C0U,01FF8U, 01FF0U,03FECU, 03FF8U,07FDEU, 03FF8U,07FBEU,
  244.   07FFCU,0FF7FU, 07EFCU,0FFFFU, 07FFCU,0FFFFU, 03FF8U,07FFEU,
  245.   03FF8U,07FFEU, 01FF0U,03FFCU, 007C0U,01FF8U, 00000U,007E0U,
  246.   00000U,00000U);
  247.  
  248.  
  249. CONST (* RawKey Codes: *)
  250.  
  251.   ESC   = 45H; HELP  = 5FH;
  252.   UP    = 4CH; DOWN  = 4DH;
  253.   SPACE = 40H; BS    = 41H;
  254.   CR    = 44H; ENTER = 43H;
  255.   NK0   = 0FH; NK1   = 1DH; NK2   = 1EH; NK3   = 1FH;
  256.   NK5   = 2EH; NK7   = 3DH; NK8   = 3EH; NK9   = 3FH;
  257.   F1    = 50H; F10   = 59H;
  258.  
  259.  
  260. CONST
  261.   ShowStackSize = 4096;
  262.   BufferSize = 2048;
  263.  
  264.   w = TRUE;
  265.   f = FALSE;
  266.  
  267.   MyIdcmp = LONGSET{I.rawKey,I.mouseButtons,I.closeWindow,I.activeWindow,I.inactiveWindow,I.newSize};
  268.  
  269. (* Control codes: *)
  270.   plain    = 11X;
  271.   italic   = 12X;
  272.   bold     = 13X;
  273.   boldit   = 14X;
  274.   ulineon  = 15X;
  275.   ulineoff = 16X;
  276.  
  277.   Italic = 0;
  278.   Bold   = 1;
  279.   Ulin   = 2;
  280.   Inv    = 3;
  281.  
  282. TYPE
  283.   String    = ARRAY 256 OF CHAR;
  284.   StringPtr = UNTRACED POINTER TO String;
  285.   CharPtr   = UNTRACED POINTER TO CHAR;
  286.   LongPtr   = UNTRACED POINTER TO LONGINT;
  287.  
  288.   TextLinePtr = UNTRACED POINTER TO TextLine;
  289.   TextLine = STRUCT
  290.                prev : TextLinePtr;
  291.                next : TextLinePtr;
  292.                len  : INTEGER;
  293.                size : INTEGER;
  294.                text : String;
  295.              END;
  296.  
  297. CONST
  298.   MaxLen = SIZE(String);
  299.  
  300. TYPE
  301.  
  302.   WBStartupPtr = UNTRACED POINTER TO STRUCT (message : e.Message)
  303.                    process    : d.ProcessId;
  304.                    segment    : e.BPTR;
  305.                    numArgs    : LONGINT;
  306.                    toolWindow : StringPtr;
  307.                    argList : UNTRACED POINTER TO ARRAY 256 OF STRUCT
  308.                                  lock : d.FileLockPtr;
  309.                                  name : StringPtr;
  310.                              END;
  311.                  END;
  312.  
  313.   DiskObjectPtr = UNTRACED POINTER TO STRUCT
  314.                     magic      : INTEGER;
  315.                     version    : INTEGER;
  316.                     gadget     : I.Gadget;
  317.                     type       : SHORTINT;
  318.                     defaultTool: StringPtr;
  319.                     toolTypes  : e.APTR;
  320.                     currentX   : LONGINT;
  321.                     currentY   : LONGINT;
  322.                     drawerData : e.APTR;
  323.                     toolWindow : StringPtr;
  324.                     stackSize  : LONGINT;
  325.                   END;
  326.  
  327.   Args = STRUCT (dummy: d.ArgsStruct)
  328.            b     : LongPtr;
  329.            c     : StringPtr;
  330.            d     : StringPtr;
  331.            e     : StringPtr;
  332.            f     : StringPtr;
  333.            i     : StringPtr;
  334.            o     : StringPtr;
  335.            p     : LongPtr;
  336.            q     : StringPtr;
  337.            s     : LongPtr;
  338.            t     : LongPtr;
  339.            u     : StringPtr;
  340.            x     : LongPtr;
  341.            w     : StringPtr;
  342.            wl    : LongPtr;
  343.            wt    : LongPtr;
  344.            ww    : LongPtr;
  345.            wh    : LongPtr;
  346.            fw    : LongPtr;
  347.            fh    : LongPtr;
  348.            file  : StringPtr;
  349.          END;
  350.  
  351. (*------  Memory:  ------*)
  352.  
  353. CONST ChunkSize = 16384;          (* size of allocated chunks *)
  354.  
  355. TYPE
  356.   MemChunkPtr = UNTRACED POINTER TO MemChunk;  (* chunklist *)
  357.  
  358.   MemChunk = STRUCT
  359.                prev: MemChunkPtr;     (* link *)
  360.                data: ARRAY ChunkSize OF CHAR; (* ChunkSize Bytes of memory *)
  361.              END;
  362.  
  363.  
  364. (*------  Globals  ------*)
  365.  
  366. VAR
  367.   pub            : I.ScreenPtr;        (* default public screen             *)
  368.   Screen         : I.ScreenPtr;        (* MuchMore's Screen                 *)
  369.   Window         : I.WindowPtr;        (* MuchMore's Window                 *)
  370.   rp             : g.RastPortPtr;      (* Screen's RastPort                 *)
  371.   BM             : g.BitMapPtr;        (* Screen's BitMap                   *)
  372.   id             : LONGINT;            (* Display ID                        *)
  373.   catalog        : loc.CatalogPtr;     (* The Catalog                       *)
  374.   MyFile         : d.FileHandlePtr;    (* For loading Textfile              *)
  375.   MyAttr         : g.TextAttr;         (* The selected Font attributes      *)
  376.   MyFont         : g.TextFontPtr;      (* The selected Font                 *)
  377.   OldFont        : g.TextFontPtr;      (* To save old Font                  *)
  378.   FontName       : String;             (* My Font Name or                   *)
  379.   FontSize       : INTEGER;            (* My Font Size                      *)
  380.   FirstLine      : TextLinePtr;        (* the topmost Line                  *)
  381.   TopLine        : TextLinePtr;        (* the topmost Line                  *)
  382.   BottomLine     : TextLinePtr;        (* Last Line displayed on Screen     *)
  383.   LoadLine       : TextLinePtr;        (* currently loaded Line             *)
  384.   LastLine       : TextLinePtr;        (* Last element of LineList          *)
  385.   writeText      : TextLine;           (* temp. Text Line                   *)
  386.   Name,OldName   : String;             (* Text's Name                       *)
  387.   option         : String;             (* CLI Option                        *)
  388.   pubscreenname  : String;
  389.   zoomBox        : ARRAY 4 OF INTEGER;
  390.   editcmd        : String;
  391.   Pens           : String;             (* Screen colors                     *)
  392.   Cols           : ARRAY 4 OF INTEGER; (* Color array for LoadRGB4          *)
  393.   busyPointer    : UNTRACED POINTER TO BusyPointer;
  394.   icon           : DiskObjectPtr;      (* info                              *)
  395.   nameptr        : StringPtr;          (* String Pointer                    *)
  396.   chptr          : CharPtr;            (* Char Pointer                      *)
  397.   PStr           : String;             (* The command for Dos.Execute       *)
  398.   Buffer         : UNTRACED POINTER TO ARRAY BufferSize OF CHAR; (* ReadBuf *)
  399.   RQPos          : LONGINT;            (* Position within ReadBuffer        *)
  400.   RQLen          : LONGINT;            (* Number of CHARs in Buffer         *)
  401.   AnzLines       : LONGINT;            (* Length of Text in Lines           *)
  402.   NumLines       : INTEGER;            (* Number of Lines on Screen         *)
  403.   fontWidth,fontHeight: INTEGER;       (* Font size                         *)
  404.   fontBaseLine   : INTEGER;            (* Font base line                    *)
  405.   spacing        : INTEGER;            (* Extra Line Spacing                *)
  406.   NumColumns     : INTEGER;            (* Number of Columns on Screen       *)
  407.   PageHeight     : INTEGER;            (* fontHeight*NumLines               *)
  408.   i,j            : INTEGER;            (* count                             *)
  409.   left,top       : INTEGER;            (* Dimensions of MMs window          *)
  410.   width,height   : INTEGER;
  411.   initialheight  : INTEGER;
  412.   depth          : INTEGER;            (* Number of planes                  *)
  413.   ci             : INTEGER;            (* Color index                       *)
  414.   scrollmode     : INTEGER;            (* The scrollmode                    *)
  415.   taskpri,oldpri : SHORTINT;           (* Muchmore's Task Priority          *)
  416.   frwidth,frheight:INTEGER;
  417.   MyLock,OldDir  : d.FileLockPtr;      (* To Examine and Load File          *)
  418.   oldcd          : d.FileLockPtr;      (* To save old CD                    *)
  419.   progdir        : d.FileLockPtr;      (* Lock on PROGDIR:                  *)
  420.   clock          : d.FileLockPtr;      (* Lock on C:                        *)
  421.   FileInfo       : d.FileInfoBlockPtr; (* to get File's length              *)
  422.   FileLength,TextLength : LONGINT;     (* Length of File and Displayed Text *)
  423.   ReadLength     : LONGINT;            (* Length of Text while reading      *)
  424.   ScreenPos      : INTEGER;            (* actual position within bitmap     *)
  425.   ShowTask       : e.TaskPtr;          (* the task that displays the text   *)
  426.   ShowStack      : e.APTR;             (* it's stack                        *)
  427.   ShowTaskRunning: BOOLEAN;            (* is Showtask activated?            *)
  428.   win            : BOOLEAN;            (* Is MM running in a window?        *)
  429.   interleaved    : BOOLEAN;            (* Use interleaved Screen?           *)
  430.   zoomed         : BOOLEAN;            (* Is MM iconified ?                 *)
  431.   stdin          : BOOLEAN;            (* Are we reading from STDIN ?       *)
  432.   SignalNewData  : BOOLEAN;            (* Signal when new data is loaded    *)
  433.   SignalAllRead  : BOOLEAN;            (* send signal at end of text        *)
  434.   Done           : BOOLEAN;            (* Quit                              *)
  435.   print          : BOOLEAN;            (* print text?                       *)
  436.   save           : BOOLEAN;            (* save block?                       *)
  437.   copy           : BOOLEAN;            (* copy block to clipboard?          *)
  438.   NewText        : BOOLEAN;            (* load new text                     *)
  439.   Info           : BOOLEAN;            (* is info currently displayed ?     *)
  440.   modeReq        : BOOLEAN;            (* Show Display Mode Requester?      *)
  441.   Scroll         : BOOLEAN;            (* scrolling or waiting?             *)
  442.   Fast           : BOOLEAN;            (* scroll quick?                     *)
  443.   Sync           : BOOLEAN;            (* scroll very quick?                *)
  444.   Decrunched     : BOOLEAN;            (* Is file decrunched?               *)
  445.   Scrollable     : BOOLEAN;            (* is screen able to scroll?         *)
  446.   refresh        : BOOLEAN;            (* Refresh Window?                   *)
  447.   oldstyle       : BOOLEAN;            (* Page Up/Down with soft scroll?    *)
  448.   lace           : BOOLEAN;            (* Is screen interlaced?             *)
  449.   cLocked        : BOOLEAN;            (* Is C: locked ?                    *)
  450.   NewDisp        : BOOLEAN;            (* need to rebuild Display ?         *)
  451.   fastquit       : BOOLEAN;
  452.   showTaskOk     : BOOLEAN;
  453.   style          : SHORTSET;           (* Text style                        *)
  454.   mySig          : LONGSET;            (* My Signal Set                     *)
  455.   showSig        : LONGSET;            (* ShowTask's Signal Set             *)
  456.   Me             : d.ProcessPtr;       (* my main task                      *)
  457.   meInt          : LONGINT;            (* for making unique filename        *)
  458.   MyMsgPtr       : I.IntuiMessagePtr;  (* for receiving Messages            *)
  459.   in,out         : d.FileHandlePtr;    (* i/o for TYPE xxx TO PRT:          *)
  460.   mySigBit       : INTEGER;            (* My Signal Bit                     *)
  461.   showSigBit     : INTEGER;            (* ShowTask's Sig Bit                *)
  462.   frame          : INTEGER;            (* Frame Count                       *)
  463.   fg,bg          : INTEGER;            (* Text colors                       *)
  464.   oldfg,oldbg    : INTEGER;            (* Old Text colors                   *)
  465.   tabw           : INTEGER;            (* Tabulator width                   *)
  466.   rd             : d.RDArgsPtr;        (* For ReadArgs                      *)
  467.   args           : Args;               (* My CLI Args                       *)
  468.   ArgPtr         : StringPtr;          (* to get WBArg                      *)
  469.   wbm            : WBStartupPtr;       (* WBenchMessage                     *)
  470.   ri             : g.RasInfoPtr;       (* Screen's ViewPort's RasInfo       *)
  471.   dims           : g.DimensionInfo;    (* Dims for KS2.0                    *)
  472.   disp           : g.DisplayInfo;      (* DisplayInfo for KS2.0             *)
  473.   StrGadget      : I.Gadget;           (* Gadget for Find-Command           *)
  474.   StrInfo        : I.StringInfo;       (* its special info                  *)
  475.   StrExt         : I.StringExtend;     (* its extension                     *)
  476.   asl            : e.LibraryPtr;       (* ASL-librarybase                   *)
  477.   diskFontBase   : e.LibraryPtr;       (* DiskFont-LibraryBase              *)
  478.   xpk            : e.LibraryPtr;       (* XpkMaster-Librarybase             *)
  479.   iconBase       : e.LibraryPtr;       (* Icon-Librarybase                  *)
  480.   Filename       : String;             (* The Filename (without path)       *)
  481.   Dirname        : String;             (* its path                          *)
  482.   Pattern        : ARRAY 80 OF CHAR;   (* The pattern for Filerequester     *)
  483.   TextMarkers    : ARRAY 10 OF TextLinePtr; (* Marked Positions in text     *)
  484.   FindLine       : TextLinePtr;        (* Last found line                   *)
  485.   KeyMap         : ARRAY 50H OF CHAR;  (* console's KeyMap                  *)
  486.   Password       : String;             (* Password for encrypted texts      *)
  487.   conreq         : e.IOStdReqPtr;      (* Console IO-Request                *)
  488.   console        : e.DevicePtr;        (* the console.device                *)
  489.   ievent         : ie.InputEventPtr;   (* InputEvent to convert keycodes    *)
  490.   WriteName      : String;             (* File to write Block               *)
  491.   savefrom,savesize: LONGINT;          (* How much to save?                 *)
  492.   iff            : ip.IFFHandlePtr;    (* IFF Handle for clipboard copy     *)
  493.   buffer         : UNTRACED POINTER TO CHAR; (* Save buffer                 *)
  494.   MemIndex       : INTEGER;            (* index in current Chunk            *)
  495.   CurChunk       : MemChunkPtr;        (* current chunk                     *)
  496.   c              : CHAR;               (* \ used by GetTextLine();          *)
  497.   le             : INTEGER;            (* / global for speed                *)
  498.  
  499.  
  500. (*-------------------------------------------------------------------------*)
  501.  
  502. PROCEDURE OpenDiskFont*{diskFontBase,-30}(VAR textAttr{8}: g.TextAttr): g.TextFontPtr;
  503.  
  504. PROCEDURE GetDiskObject {iconBase,- 78}(name{8}        : ARRAY OF CHAR): DiskObjectPtr;
  505. PROCEDURE FreeDiskObject{iconBase,- 90}(diskobj{8}     : DiskObjectPtr);
  506. PROCEDURE FindToolType  {iconBase,- 96}(toolTypes{8}   : e.APTR;
  507.                                         typeName{9}    : ARRAY OF CHAR): StringPtr;
  508. PROCEDURE MatchToolValue{iconBase,-102}(typeString{8}  : ARRAY OF CHAR;
  509.                                         val{9}         : ARRAY OF CHAR): BOOLEAN;
  510.  
  511. (*-------------------------  ASL Stuff:  ----------------------------------*)
  512.  
  513. CONST
  514.   aslTag  = u.user + 80000H;
  515.  
  516.   taghail   = aslTag + 1;
  517.   window    = aslTag + 2;
  518.   leftEdge  = aslTag + 3;
  519.   topEdge   = aslTag + 4;
  520.   tagWidth  = aslTag + 5;
  521.   tagHeight = aslTag + 6;
  522.   hookFunc  = aslTag + 7;
  523.   file      = aslTag + 8;
  524.   dir       = aslTag + 9;
  525.   pattern   = aslTag + 10;
  526.   funcFlags = aslTag + 20;
  527.   screen    = aslTag + 40;
  528.   sleepWindow=aslTag + 43;
  529.   fiDir     = u.user + 50;
  530.   patGad    = 0;
  531.   fileRequest        = 0;
  532.   screenModeRequest  = 2;
  533.   smPropertyFlags = aslTag+114;
  534.   smPropertyMask  = aslTag+115;
  535.   titleText       = aslTag+1;
  536.   initialDisplayID= aslTag+100;
  537.  
  538. TYPE
  539.   ASLRequesterPtr = UNTRACED POINTER TO ASLRequester;
  540.   ScreenModeRequesterPtr = UNTRACED POINTER TO ScreenModeRequester;
  541.   FileRequesterPtr = UNTRACED POINTER TO FileRequester;
  542.  
  543.   ASLRequester = STRUCT END;
  544.  
  545.   FileRequester = STRUCT (dummy: ASLRequester)
  546.     reserved0 : ARRAY 4 OF e.UBYTE;
  547.     file      : e.STRPTR;
  548.     dir       : e.STRPTR;
  549.     reserved1 : ARRAY 10 OF e.UBYTE;
  550.     leftEdge  : INTEGER;
  551.     topEdge   : INTEGER;
  552.     width     : INTEGER;
  553.     height    : INTEGER;
  554.     reserved2 : ARRAY 2 OF e.UBYTE;
  555.     numArgs   : LONGINT;
  556.     argList   : e.APTR;
  557.     userData  : e.APTR;
  558.     reserved3 : ARRAY 8 OF e.UBYTE;
  559.     pat       : e.STRPTR;
  560.   END;
  561.  
  562.   ScreenModeRequester = STRUCT (dummy: ASLRequester)
  563.     displayID      : LONGINT;
  564.     displayWidth   : LONGINT;
  565.     displayHeight  : LONGINT;
  566.     displayDepth   : INTEGER;
  567.     overscanType   : INTEGER;
  568.     autoScroll     : BOOLEAN;
  569.     pad1           : SHORTINT;
  570.     bitMapWidth    : LONGINT;
  571.     bitMapHeight   : LONGINT;
  572.     leftEdge       : INTEGER;
  573.     topEdge        : INTEGER;
  574.     width          : INTEGER;
  575.     height         : INTEGER;
  576.     infoOpened     : BOOLEAN;
  577.     pad2           : SHORTINT;
  578.     infoLeftEdge   : INTEGER;
  579.     infoTopEdge    : INTEGER;
  580.     infoWidth      : INTEGER;
  581.     infoHeight     : INTEGER;
  582.     userData       : e.APTR;
  583.   END;
  584.  
  585.  
  586. PROCEDURE AllocAslRequestTags{asl,- 48}(reqType{0}: LONGINT; tag1{8}.. : u.Tag): ASLRequesterPtr;
  587. PROCEDURE FreeAslRequest     {asl,- 54}(requester{8}: ASLRequesterPtr);
  588. PROCEDURE AslRequestTags     {asl,- 60}(requester{8}: ASLRequesterPtr; tag1{9}.. : u.Tag): BOOLEAN;
  589.  
  590.  
  591. (*-------------------------------------------------------------------------*)
  592.  
  593. (* $Debug- *)
  594.  
  595. PROCEDURE StuffChar; (* $EntryExitCode- *)
  596. BEGIN
  597.   SYS.INLINE(016C0U, 04E75U)
  598. END StuffChar;
  599.  
  600.  
  601. (*-------------------------------------------------------------------------*)
  602.  
  603.  
  604. PROCEDURE LocStr (num: LONGINT): e.LSTRPTR;
  605. VAR default: e.LSTRPTR;
  606.  
  607. BEGIN
  608.   default := MSGS[num];
  609.   IF loc.base=NIL THEN RETURN default
  610.                   ELSE RETURN loc.GetCatalogStr(catalog,num,default^) END;
  611. END LocStr;
  612.  
  613.  
  614. (*-----------------------------  Requester:  ------------------------------*)
  615.  
  616.  
  617. PROCEDURE Error(Text: ARRAY OF CHAR); (* $CopyArrays- *)
  618. VAR es: I.EasyStruct;
  619.  
  620. BEGIN
  621.   IF ol.wbStarted THEN
  622.     es.structSize   := SIZE(I.EasyStruct);
  623.     es.flags        := LONGSET{};
  624.     es.title        := SYS.ADR(MuchText);
  625.     es.textFormat   := SYS.ADR(Text);
  626.     es.gadgetFormat := LocStr(MSGOK);
  627.     IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN END;
  628.   ELSE
  629.     SYS.SETREG(0,d.Write(d.Output(),Text,str.Length(Text)));
  630.     SYS.SETREG(0,d.Write(d.Output(),"\n",1));
  631.   END;
  632.   HALT(d.fail);
  633. END Error;
  634.  
  635.  
  636. PROCEDURE OutOfMemHandler;
  637. VAR es: I.EasyStruct;
  638.  
  639. BEGIN
  640.   es.structSize   := SIZE(I.EasyStruct);
  641.   es.flags        := LONGSET{};
  642.   es.title        := SYS.ADR(MuchText);
  643.   es.textFormat   := LocStr(MSGOOM);
  644.   es.gadgetFormat := LocStr(MSGRETRYABORT);
  645.   IF I.EasyRequest(NIL,SYS.ADR(es),NIL,NIL)=0 THEN
  646.     HALT(d.fail)
  647.   END;
  648. END OutOfMemHandler;
  649.  
  650.  
  651. (*-------------------------------------------------------------------------*)
  652.  
  653.  
  654. PROCEDURE AllocLine(sz: INTEGER): TextLinePtr;
  655.  
  656. VAR newchunk: MemChunkPtr;
  657.  
  658. BEGIN
  659.   INC(sz,SIZE(TextLine)-MaxLen); IF ODD(sz) THEN INC(sz) END;
  660.   IF MemIndex+sz<=ChunkSize THEN     (* does mem fit into current chunk ? *)
  661.     INC(MemIndex,sz);                (* increment index in current chunk  *)
  662.   ELSE
  663.     NEW(newchunk);                   (* allocate new chunk                *)
  664.     newchunk.prev := CurChunk;       (* link chunk into list              *)
  665.     CurChunk := newchunk;
  666.     MemIndex := sz;
  667.   END;
  668.   RETURN SYS.ADR(CurChunk.data[MemIndex-sz]);
  669. END AllocLine;
  670.  
  671.  
  672. PROCEDURE DisposeLines();
  673.  
  674. VAR chunk: MemChunkPtr;
  675.  
  676. BEGIN
  677.   WHILE CurChunk#NIL DO
  678.     chunk := CurChunk.prev;
  679.     DISPOSE(CurChunk);
  680.     CurChunk := chunk;
  681.   END;
  682.   MemIndex := ChunkSize;
  683. END DisposeLines;
  684.  
  685.  
  686. (*-------------------------------------------------------------------------*)
  687.  
  688.  
  689. PROCEDURE Busy;
  690. BEGIN
  691.   IF Window # NIL THEN
  692.     I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.rawKey,I.mouseButtons});
  693.     IF I.base.libNode.version >= 39 THEN
  694.       I.SetWindowPointer(Window,I.waBusyPointer,I.LTRUE,u.done);
  695.     ELSE
  696.       I.SetPointer(Window,busyPointer^,16,16,-6,0);
  697.     END;
  698.   END;
  699. END Busy;
  700.  
  701.  
  702. PROCEDURE UnBusy;
  703. BEGIN
  704.   IF Window # NIL THEN
  705.     IF I.base.libNode.version >= 39 THEN
  706.       I.SetWindowPointer(Window,u.done);
  707.     ELSE
  708.       I.ClearPointer(Window);
  709.     END;
  710.     I.OldModifyIDCMP(Window,MyIdcmp);
  711.   END;
  712. END UnBusy;
  713.  
  714.  
  715. (*------  Scroll:  ------*)
  716.  
  717. PROCEDURE ScrollDisplay (sync,fast,always: BOOLEAN);
  718. VAR m: INTEGER;
  719.  
  720. BEGIN
  721.   IF Scrollable THEN
  722.     m := 1;
  723.     IF ~always THEN
  724.       IF lace & ~fast THEN m := 2 END;
  725.       IF ~sync THEN INC(m,m*2) END;
  726.     END;
  727.     IF (m=1) OR (frame MOD m=0) THEN
  728.  
  729.       CASE scrollmode OF
  730.  
  731.       | 1: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  732.            g.WaitTOF;
  733.  
  734.       | 2: I.OldMakeScreen(Screen);
  735.            I.OldRethinkDisplay();
  736.  
  737.       (* 3: ScrollRaster *)
  738.  
  739.       | 4: g.WaitTOF;
  740.            g.ScrollVPort(SYS.ADR(Screen.viewPort));
  741.  
  742.       | 5: g.ScrollVPort(SYS.ADR(Screen.viewPort));
  743.            g.WaitBOVP(SYS.ADR(Screen.viewPort));
  744.  
  745.       ELSE (* 0: *)
  746.            I.OldMakeScreen(Screen);
  747.            e.Forbid; SYS.SETREG(0,g.MrgCop(I.ViewAddress())); e.Permit;
  748.            g.WaitTOF;
  749.  
  750.       END;
  751.     END;
  752.     (* $OvflChk- *)
  753.     INC(frame);
  754.     (* $OvflChk= *)
  755.   END;
  756. END ScrollDisplay;
  757.  
  758.  
  759. (*------  Clear Display:  ------*)
  760.  
  761. PROCEDURE ClearDisplay;
  762. BEGIN
  763.   IF win THEN
  764.     g.SetAPen(rp,0);
  765.     g.RectFill(rp,left,top,left+width-1,top+height-1);
  766.   ELSE
  767.     g.SetRast(rp,0);
  768.   END;
  769.   IF Scrollable THEN
  770.     ri.ryOffset := 0;
  771.     ScreenPos := 0;
  772.     ScrollDisplay(f,f,w);
  773.   END;
  774. END ClearDisplay;
  775.  
  776. (*-------------------------------------------------------------------------*)
  777.  
  778. (*------  Read one TextLine into a Variable:  ------*)
  779.  
  780.  
  781. PROCEDURE GetTextLine(): TextLinePtr;
  782. (* returns NIL at EOF *)
  783.  
  784. VAR
  785.   l        : TextLinePtr;
  786.   sz,wd,i,j: INTEGER;
  787.   cnt      : INTEGER;
  788.   txt      : ARRAY MaxLen+1 OF CHAR;
  789.   num      : ARRAY 10 OF INTEGER;
  790.   newcol   : BOOLEAN;
  791.   oldstyle : SHORTSET;
  792.  
  793.   PROCEDURE GetCh();
  794.   BEGIN
  795.     IF RQPos=RQLen THEN
  796.       RQLen := d.Read(MyFile,Buffer^,BufferSize);
  797.       IF RQLen<0 THEN Error(LocStr(MSGRWERR)^) END;
  798.       RQPos := 0;
  799.     END;
  800.     IF RQLen=0 THEN
  801.       c := 0X
  802.     ELSE
  803.       c := Buffer[RQPos];
  804.       IF c=0X THEN c:=1X END;
  805.       INC(RQPos); INC(le);
  806.     END;
  807.   END GetCh;
  808.  
  809. BEGIN
  810.   IF RQLen=0 THEN RETURN NIL END;
  811.  
  812.   sz := 0; wd := 0; le := 0; cnt := 0;
  813.  
  814.   IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END; INC(sz)
  815.                      ELSE IF Bold IN style THEN txt[sz] := bold; INC(sz) END                      END;
  816.   IF   Ulin IN style     THEN txt[sz] := ulineon; INC(sz) END;
  817.   IF    Inv IN style     THEN txt[sz] := CHR(fg+4*bg+1); INC(sz)
  818.   ELSIF (fg#1) OR (bg#0) THEN txt[sz] := CHR(bg+4*fg+1); INC(sz) END;
  819.  
  820.   LOOP
  821.     LOOP
  822.       GetCh;
  823.       IF (c#1BX) & (c#9BX) THEN EXIT END;
  824.       i := -1;
  825.       REPEAT
  826.         GetCh;
  827.         IF (c>="0") & (c<="9") THEN
  828.           INC(i); num[i] := 0;
  829.           REPEAT
  830.             num[i] := 10*num[i]+(ORD(c)-ORD("0")); GetCh;
  831.           UNTIL (c<"0") OR (c>"9");
  832.         END;
  833.         c := CAP(c);
  834.       UNTIL (c>="?") & (c<="Z") OR (c=0X) OR (i=9);
  835.       IF c="M" THEN
  836.         newcol := f; oldstyle := style; j := 0;
  837.         IF i=-1 THEN i:=0; num[0] := 0 END;
  838.         WHILE (i>=j) & (sz<MaxLen-1) DO
  839.           CASE num[j] OF
  840.           0:  style := SHORTSET{}; fg := 1; bg := 0; newcol := w |
  841.           1:  INCL(style,Bold) |
  842.           2:  fg := 2; newcol := w |
  843.           3:  INCL(style,Italic) |
  844.           4:  INCL(style,Ulin) |
  845.           7:  INCL(style,Inv); newcol := w |
  846.           8:  oldfg:=fg; oldbg:=bg; fg:=0; bg:=0; newcol := w |
  847.  
  848.           22: EXCL(style,Bold); fg := 1; newcol := w |
  849.           23: EXCL(style,Italic) |
  850.           24: EXCL(style,Ulin) |
  851.           27: EXCL(style,Inv); newcol := w |
  852.           28: fg:=oldfg; bg:=oldbg; newcol := w |
  853.  
  854.           30..37: fg := (num[j]-30) MOD 4; newcol := w |
  855.           39:     fg := 1; newcol := w |
  856.  
  857.           40..47: bg := (num[j]-40) MOD 4; newcol := w |
  858.           49:     bg := 0; newcol := w |
  859.  
  860.           ELSE END;
  861.           INC(j);
  862.         END;
  863.         IF (oldstyle#style) & (sz<MaxLen) THEN
  864.           IF Italic IN style THEN IF Bold IN style THEN txt[sz] := boldit ELSE txt[sz] := italic END;
  865.                              ELSE IF Bold IN style THEN txt[sz] := bold   ELSE txt[sz] := plain  END;
  866.           END;
  867.           INC(sz);
  868.           IF (Ulin IN style) THEN
  869.             IF ~((Ulin IN oldstyle)) & (sz<MaxLen) THEN
  870.               txt[sz] := ulineon;
  871.               INC(sz);
  872.             END;
  873.           ELSE
  874.             IF (Ulin IN oldstyle) & (sz<MaxLen) THEN
  875.               txt[sz] := ulineoff;
  876.               INC(sz);
  877.             END;
  878.           END;
  879.         END;
  880.         IF newcol & (sz<MaxLen) THEN
  881.           IF Inv IN style THEN txt[sz] := CHR(fg+4*bg+1)
  882.                           ELSE txt[sz] := CHR(bg+4*fg+1) END;
  883.           INC(sz);
  884.         END;
  885.       END;   (* IF c="m" THEN *)
  886.     END;   (* LOOP *)
  887.  
  888.     CASE c OF
  889.       (*
  890.       020X.. 7FX:   txt[sz] := c; INC(sz); INC(wd) |
  891.       0A1X..0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  892.       *)
  893.  
  894.       020X.. 0FFX:   txt[sz] := c; INC(sz); INC(wd) |
  895.  
  896.       8X: (* BS *)  IF wd>0 THEN DEC(sz); DEC(wd); END |
  897.       9X: (* TAB *) REPEAT
  898.                       txt[sz] := 20X; INC(sz); INC(wd)
  899.                     UNTIL (sz=MaxLen) OR (wd=NumColumns) OR (sz MOD tabw=0) |
  900.       (*0A0X:         txt[sz] := 20X; INC(sz); INC(wd) |*)
  901.       0X,0AX,0CX:   EXIT
  902.     ELSE
  903.     END;
  904.     IF (wd>=NumColumns) OR (sz>=MaxLen) THEN EXIT END;
  905.   END;
  906.   txt[sz] := 0X; INC(sz);
  907.   l := AllocLine(sz);
  908.   l.len := le; l.size:= sz;
  909.   WHILE sz>0 DO DEC(sz); l.text[sz] := txt[sz] END;
  910.   INC(ReadLength,le);
  911.  
  912.   RETURN l;
  913. END GetTextLine;
  914.  
  915.  
  916. (*------  Write Line to Screen:  ------*)
  917.  
  918.  
  919. PROCEDURE Type (pos: INTEGER; line: TextLinePtr);
  920.  
  921. VAR
  922.   style: SHORTSET;
  923.   front,back: SHORTINT;
  924.   c: CHAR;
  925.   last,i,x,y: INTEGER;
  926.   strPtr: StringPtr;
  927.  
  928. BEGIN
  929.   g.SetDrMd(rp,g.jam2);
  930.   IF Scrollable THEN
  931.     g.SetAPen(rp,0);
  932.     y := pos * fontHeight;
  933.     IF ~refresh THEN g.RectFill(rp,0,y,width-1,y+fontHeight-spacing-1) END;
  934.   END;
  935.   i := 0; x := 0; style := SHORTSET{}; front := 1; back := 0;
  936.   LOOP
  937.     WHILE line.text[i] < " " DO
  938.       c := line.text[i];
  939.       IF c=0X THEN EXIT END;
  940.       CASE c OF
  941.       plain   : style := style - SHORTSET{g.bold,g.italic} |
  942.       italic  : EXCL(style,g.bold); INCL(style,g.italic)   |
  943.       bold    : INCL(style,g.bold); EXCL(style,g.italic)   |
  944.       boldit  : style := style + SHORTSET{g.bold,g.italic} |
  945.       ulineon : INCL(style,g.underlined) |
  946.       ulineoff: EXCL(style,g.underlined) |
  947.       1X..10X : DEC(c);
  948.                 front := SHORT(ORD(c)) DIV 4;
  949.                 back  := SHORT(ORD(c)) MOD 4 |
  950.       ELSE END;
  951.       INC(i);
  952.     END;
  953.     strPtr := SYS.ADR(line.text[i]); last := i;
  954.     REPEAT INC(i) UNTIL line.text[i]<" ";
  955.     SYS.SETREG(0,g.SetSoftStyle(rp,style,-SHORTSET{}));
  956.     g.SetAPen(rp,front);
  957.     g.SetBPen(rp,back);
  958.     g.Move(rp,left+fontWidth*x,top+fontHeight*pos+fontBaseLine);
  959.     g.Text(rp,strPtr^,i-last);
  960.     INC(x,i-last);
  961.   END;
  962. END Type;
  963.  
  964.  
  965. PROCEDURE CopyScrollLine(pos: INTEGER);
  966. (* Kopiert die an pos geschriebene Zeile auf den entsprechenden
  967.  * DoubleBuffer-Bereich
  968.  * ACHTUNG: Darf nur aufgerufen werden, wenn Scrollable TRUE ist!
  969.  *)
  970.  
  971. VAR
  972.   y,z: INTEGER;
  973.  
  974. BEGIN
  975.   y := pos*fontHeight;
  976.   z := PageHeight;
  977.   IF pos >= NumLines THEN z := -z END;
  978.   SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+z, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  979. END CopyScrollLine;
  980.  
  981.  
  982. (*------  Copy String to TextLine:  ------*)
  983.  
  984.  
  985. PROCEDURE CopyToWriteText (String: StringPtr);
  986. VAR i,j : INTEGER;
  987.  
  988. BEGIN
  989.   e.CopyMem(String^,writeText.text,MaxLen-1);
  990.   j := 0;
  991.   FOR i := 0 TO SHORT(str.Length(writeText.text))-1 DO
  992.     IF writeText.text[i] >= " " THEN INC(j) END;
  993.     IF j >= NumColumns THEN
  994.       writeText.text[i] := 0X;
  995.       RETURN
  996.     END;
  997.   END;
  998. END CopyToWriteText;
  999.  
  1000.  
  1001. (*------  Write String to Screen (at any position):  ------*)
  1002.  
  1003.  
  1004. PROCEDURE TypeTo (VAR text: TextLine; pos: INTEGER);
  1005.  
  1006. BEGIN
  1007.   IF pos < NumLines THEN
  1008.     IF Scrollable THEN
  1009.       INC(pos,ScreenPos);
  1010.       Type(pos,SYS.ADR(text));
  1011.       CopyScrollLine(pos);
  1012.     ELSE
  1013.       Type(pos,SYS.ADR(text));
  1014.     END;
  1015.   END;
  1016. END TypeTo;
  1017.  
  1018.  
  1019. (*------  Write String to Screen (at any position):  ------*)
  1020.  
  1021.  
  1022. PROCEDURE WriteTo (String: StringPtr; pos: INTEGER);
  1023.  
  1024. BEGIN
  1025.   CopyToWriteText(String);
  1026.   TypeTo(writeText,pos);
  1027. END WriteTo;
  1028.  
  1029.  
  1030. (*------  Write Line at Bottom of Text:  ------*)
  1031.  
  1032.  
  1033. PROCEDURE AddBottomLine (Line: TextLinePtr; Fast: BOOLEAN);
  1034. VAR i,y: INTEGER;
  1035.  
  1036. BEGIN
  1037.   IF ~Scrollable THEN
  1038.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1039.     IF Fast THEN
  1040.       g.ScrollRaster(rp,0,fontHeight,left,top,left+width-1,top+height-1);
  1041.       IF Sync THEN g.WaitTOF END;
  1042.     ELSE
  1043.       i := fontHeight;
  1044.       REPEAT
  1045.         IF Window.height=initialheight THEN (* Prevent crash under v37 *)
  1046.           g.ScrollRaster(rp,0,1,left,top,left+width-1,top+height-1);
  1047.         END;
  1048.         IF Sync THEN g.WaitTOF END;
  1049.         DEC(i);
  1050.       UNTIL i=0;
  1051.     END;
  1052.     Type(NumLines-1,Line);
  1053.   ELSE
  1054.     Type(ScreenPos+NumLines,Line);
  1055.     y := ScreenPos*fontHeight;
  1056.     IF Fast THEN
  1057.       INC(ri.ryOffset,fontHeight);
  1058.       ScrollDisplay(Sync,w,f);
  1059.       SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,fontHeight, 0C0X, SHORTSET{0..7}, NIL));
  1060.     ELSE
  1061.       i := fontHeight;
  1062.       REPEAT
  1063.         INC(ri.ryOffset);
  1064.         ScrollDisplay(Sync,f,f);
  1065.         SYS.SETREG(0,g.BltBitMap(BM, 0,y+PageHeight, BM, 0,y, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1066.         INC(y);
  1067.         DEC(i);
  1068.       UNTIL i=0;
  1069.     END;
  1070.     INC(ScreenPos);
  1071.     IF ScreenPos=NumLines THEN
  1072.       ScreenPos := 0;
  1073.       ri.ryOffset := 0;
  1074.     END;
  1075.   END;
  1076. END AddBottomLine;
  1077.  
  1078.  
  1079. (*------  Check whether BottomLine.next is NIL or not:  ------*)
  1080.  
  1081.  
  1082. PROCEDURE TryBottomnext(): BOOLEAN;
  1083. (* returns TRUE if BottomLine.next#NIL END; *)
  1084.  
  1085. BEGIN
  1086.   IF (BottomLine.next=NIL) & (MyFile#NIL) THEN
  1087.     SignalNewData := w;
  1088.     SYS.SETREG(0,e.Wait(showSig));
  1089.     SignalNewData := f;
  1090.   END;
  1091.   RETURN BottomLine.next#NIL;
  1092. END TryBottomnext;
  1093.  
  1094.  
  1095. (*------  Scroll down one Line:  ------*)
  1096.  
  1097.  
  1098. PROCEDURE ScrollDown(Fast: BOOLEAN);
  1099.  
  1100. BEGIN
  1101.   IF TryBottomnext() THEN
  1102.     BottomLine := BottomLine.next;
  1103.     INC(AnzLines);
  1104.     INC(TextLength,BottomLine.len);
  1105.   ELSE RETURN END;
  1106.   IF AnzLines >= NumLines THEN TopLine := TopLine.next END;
  1107.   AddBottomLine(BottomLine,Fast);
  1108. END ScrollDown;
  1109.  
  1110.  
  1111. (*------  Scroll Up one Line:  ------*)
  1112.  
  1113.  
  1114. PROCEDURE ScrUp (Fast: BOOLEAN);
  1115. VAR
  1116.   i,y: INTEGER;
  1117.  
  1118. BEGIN
  1119.   IF ~Scrollable THEN
  1120.     g.SetAPen(rp,0); g.SetBPen(rp,0);
  1121.     IF Fast THEN
  1122.       g.ScrollRaster(rp,0,-fontHeight,left,top,left+width-1,top+height-1);
  1123.       IF Sync THEN g.WaitTOF END;
  1124.     ELSE
  1125.       i := fontHeight;
  1126.       REPEAT
  1127.         IF Window.height=initialheight THEN
  1128.           g.ScrollRaster(rp,0,-1,left,top,left+width-1,top+height-1);
  1129.         END;
  1130.         IF Sync THEN g.WaitTOF END;
  1131.         DEC(i)
  1132.       UNTIL i=0;
  1133.     END;
  1134.     IF TopLine.prev#NIL THEN Type(0,TopLine.prev) ELSE Type(0,FirstLine) END;
  1135.   ELSE
  1136.     IF ScreenPos=0 THEN
  1137.       ri.ryOffset := NumLines*fontHeight;
  1138.       ScreenPos := NumLines;
  1139.     END;
  1140.     DEC(ScreenPos);
  1141.     IF TopLine.prev#NIL THEN Type(ScreenPos,TopLine.prev) ELSE Type(ScreenPos,FirstLine) END;
  1142.     y := ScreenPos*fontHeight;
  1143.     IF Fast THEN
  1144.       DEC(ri.ryOffset,fontHeight);
  1145.       ScrollDisplay(Sync,w,f);
  1146.       SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,fontHeight , 0C0X, SHORTSET{0..7}, NIL));
  1147.     ELSE
  1148.       INC(y,fontHeight);
  1149.       i := fontHeight;
  1150.       REPEAT
  1151.         DEC(ri.ryOffset);
  1152.         ScrollDisplay(Sync,f,f);
  1153.         DEC(y);
  1154.         SYS.SETREG(0,g.BltBitMap(BM, 0,y, BM, 0,y+PageHeight, width,1, 0C0X, SHORTSET{0..7}, NIL));
  1155.         DEC(i);
  1156.       UNTIL i=0;
  1157.     END;
  1158.   END;
  1159. END ScrUp;
  1160.  
  1161.  
  1162. PROCEDURE ScrollUp (Fast: BOOLEAN);
  1163.  
  1164. BEGIN
  1165.   IF (TopLine.prev#NIL) & (TopLine.prev.prev#NIL) THEN
  1166.     TopLine := TopLine.prev;
  1167.     DEC(TextLength,BottomLine.len);
  1168.     DEC(AnzLines);
  1169.     BottomLine := BottomLine.prev;
  1170.     ScrUp(Fast);
  1171.   END;
  1172. END ScrollUp;
  1173.  
  1174.  
  1175. (*------  Undo last AddBottomLine:  ------*)
  1176.  
  1177.  
  1178. PROCEDURE DelLine (Fast: BOOLEAN);
  1179.  
  1180. BEGIN
  1181.   ScrUp(Fast);
  1182.   Info := f;
  1183. END DelLine;
  1184.  
  1185.  
  1186. (*------  Convert String to Integer:  ------*)
  1187.  
  1188. PROCEDURE StrToInt (str: StringPtr; base: INTEGER): LONGINT;
  1189.  
  1190. VAR
  1191.   i,j: INTEGER;
  1192.   num: LONGINT;
  1193.   ch : CHAR;
  1194.   neg: BOOLEAN;
  1195.  
  1196. BEGIN
  1197.   num := 0; i := 0; neg := f;
  1198.   IF  str^[0] = '-'                   THEN str:=SYS.ADR(str[1]); neg := w END;
  1199.   IF  str^[0] = '$'                   THEN str:=SYS.ADR(str[1]); base:=16 END;
  1200.   IF (str^[0]='0')&(CAP(str^[1])='X') THEN str:=SYS.ADR(str[2]); base:=16 END;
  1201.   LOOP
  1202.     IF i=LEN(str^) THEN EXIT END;
  1203.     ch := CAP(str^[i]);
  1204.     IF ch=0X THEN EXIT END;
  1205.     j := ORD(ch);
  1206.     CASE ch OF
  1207.       "0".."9": DEC(j,ORD('0'))   |
  1208.       "A".."F": DEC(j,ORD('A')-10);
  1209.                 IF base=10 THEN base:=16; i:=-1; j:=0; num:=0 END;
  1210.       ELSE EXIT
  1211.     END;
  1212.     num := num * base + j;
  1213.     INC(i);
  1214.   END;
  1215.   IF neg THEN num := -num END;
  1216.   RETURN num
  1217. END StrToInt;
  1218.  
  1219.  
  1220. (*-------------------------------------------------------------------------*)
  1221.  
  1222.  
  1223. PROCEDURE GetLength (t: TextLinePtr);
  1224.  
  1225. BEGIN
  1226.   TextLength := 0; AnzLines := 0;
  1227.   WHILE t#NIL DO INC(AnzLines); INC(TextLength,t.len); t := t.prev END;
  1228. END GetLength;
  1229.  
  1230.  
  1231. (*-------------------------------------------------------------------------*)
  1232.  
  1233.  
  1234. PROCEDURE NewDisplay;
  1235. (* Zeichnet ab BottomLine neu *)
  1236.  
  1237. VAR
  1238.   i: INTEGER;
  1239.   l: TextLinePtr;
  1240.  
  1241. BEGIN
  1242.   IF ~refresh THEN ClearDisplay END;
  1243.   l := BottomLine.prev;
  1244.   IF l#NIL THEN BottomLine := l END;
  1245.   l := BottomLine;
  1246.   i := NumLines-1;
  1247.   WHILE (i>0) & TryBottomnext() DO
  1248.     BottomLine := BottomLine.next;
  1249.     DEC(i);
  1250.   END;
  1251.   WHILE (i>0) & (l.prev#NIL) DO
  1252.     l := l.prev;
  1253.     DEC(i);
  1254.   END;
  1255.   TopLine := l.next;
  1256.   WHILE i<NumLines DO
  1257.     BottomLine := l;
  1258.     TypeTo(BottomLine^,i);
  1259.     INC(i);
  1260.     l := l.next;
  1261.   END;
  1262.   GetLength(BottomLine);
  1263.   Scroll := f;
  1264.   Info := f;
  1265. END NewDisplay;
  1266.  
  1267.  
  1268. (*-------------------------------------------------------------------------*)
  1269.  
  1270.  
  1271. PROCEDURE GetString (VAR str: ARRAY OF CHAR; int,newdisp,hide: BOOLEAN);
  1272. VAR
  1273.   Win: I.WindowPtr;
  1274.   msg: I.IntuiMessagePtr;
  1275.   class: LONGSET;
  1276.   l,t,w,h: INTEGER;
  1277.   screen: I.ScreenPtr;
  1278.  
  1279. BEGIN
  1280.   ScrollDisplay(f,f,TRUE);
  1281.   Busy;
  1282.   screen := Screen;
  1283.   w := width DIV 4 * 3;
  1284.   l := (width-w) DIV 2;
  1285.   t := height DIV 2;
  1286.   IF Screen # NIL THEN
  1287.     IF Scrollable THEN INC(t,ri.ryOffset) END;
  1288.     h := Screen.font.ySize+4;
  1289.   ELSE
  1290.     screen := Window.wScreen;
  1291.     INC(l,Window.leftEdge);
  1292.     INC(t,Window.topEdge);
  1293.     h := screen.font.ySize+4;
  1294.   END;
  1295.   StrGadget.leftEdge   := 4;
  1296.   StrGadget.topEdge    := 2;
  1297.   StrGadget.width      := w-8;
  1298.   StrGadget.height     := h-4;
  1299.   StrGadget.activation := {I.stringCenter,I.relVerify};
  1300.   IF int THEN INCL(StrGadget.activation,I.longint) END;
  1301.   StrGadget.flags      := {};
  1302.   StrGadget.gadgetType := I.strGadget;
  1303.   StrGadget.specialInfo:= SYS.ADR(StrInfo);
  1304.   StrInfo.buffer       := SYS.ADR(str);
  1305.   StrInfo.maxChars     := SHORT(LEN(str))-1;
  1306.   StrInfo.extension    := SYS.ADR(StrExt);
  1307.   IF hide THEN INCL(StrGadget.flags,I.stringExtend) END;
  1308.  
  1309.   IF Scrollable THEN Screen.height := Screen.height * 2 END;
  1310.  
  1311.   Win := I.OpenWindowTagsA(NIL,
  1312.                            I.waLeft,  l,
  1313.                            I.waTop,   t,
  1314.                            I.waWidth, w,
  1315.                            I.waHeight,h,
  1316.                            I.waIDCMP, LONGSET{I.gadgetUp,I.activeWindow,I.inactiveWindow},
  1317.                            I.waFlags, LONGSET{I.rmbTrap,I.activate,I.noCareRefresh},
  1318.                            I.waGadgets,SYS.ADR(StrGadget),
  1319.                            I.waCustomScreen,screen,
  1320.                            u.done);
  1321.  
  1322.   IF Scrollable THEN Screen.height := Screen.height DIV 2 END;
  1323.  
  1324.   IF Win # NIL THEN
  1325.     e.WaitPort(Win.userPort);
  1326.     SYS.SETREG(0,I.ActivateGadget(StrGadget,Win,NIL));
  1327.     LOOP
  1328.       e.WaitPort(Win.userPort);
  1329.       msg := e.GetMsg(Win.userPort);
  1330.       IF msg # NIL THEN
  1331.         class := msg.class;
  1332.         e.ReplyMsg(msg);
  1333.         IF (I.gadgetUp IN class) OR (I.inactiveWindow IN class) THEN
  1334.           EXIT
  1335.         END;
  1336.       END;
  1337.     END;
  1338.     I.CloseWindow(Win); Win := NIL;
  1339.   END;
  1340.   UnBusy;
  1341.   IF newdisp & ~win THEN
  1342.     refresh := TRUE; BottomLine := TopLine; NewDisplay; refresh := f;
  1343.   END;
  1344. END GetString;
  1345.  
  1346.  
  1347. (*-------------------------------------------------------------------------*)
  1348.  
  1349.  
  1350. PROCEDURE * ShowProc;
  1351.  
  1352. VAR
  1353.   l           : TextLinePtr;
  1354.   Down        : BOOLEAN;          (* Scroll-Direction                  *)
  1355.   Shift       : BOOLEAN;          (* Shifted Keystroke ?               *)
  1356.   Alt         : BOOLEAN;          (* Altered Keystroke ?               *)
  1357.   wasInfo     : BOOLEAN;          (* was Info line displayed ?         *)
  1358.   found       : BOOLEAN;          (* TRUE, if find was successful      *)
  1359.   chr         : CHAR;             (* converted keycode                 *)
  1360.   caseDelta   : SHORTINT;         (* Case sensitive Search?            *)
  1361.   flen        : INTEGER;          (* length of findstring              *)
  1362.   i,j         : INTEGER;          (* Count                             *)
  1363.   Class       : LONGSET;          (* contains Message.class            *)
  1364.   Code        : INTEGER;          (* contains Message.code             *)
  1365.   Qualifier   : SET;              (* contains Message.qualifier        *)
  1366.   Find,FindStr: ARRAY 80 OF CHAR; (* findstring / capital findstring   *)
  1367.   Goto        : ARRAY 10 OF CHAR; (* string containing goto line #     *)
  1368.   li          : LONGINT;          (* longint value of line to go to    *)
  1369.   HiText      : TextLine;         (* Highlited textline                *)
  1370.   OldHiText   : TextLinePtr;      (* original, un-hilited text         *)
  1371.   skipTab     : ARRAY 256 OF INTEGER;(* for Boyer-Moore Alg.           *)
  1372.  
  1373.  
  1374.   PROCEDURE WaitAllRead();
  1375.  
  1376.   BEGIN
  1377.     IF MyFile # NIL THEN
  1378.       Busy;
  1379.       SignalAllRead := w;
  1380.       SYS.SETREG(0,e.Wait(showSig));
  1381.       SignalAllRead := f;
  1382.       UnBusy;
  1383.     END;
  1384.   END WaitAllRead;
  1385.  
  1386.  
  1387.   PROCEDURE HiLite(at,len: INTEGER);
  1388.   (* Hilites len chars of BottomLine.text starting at position at *)
  1389.  
  1390.   VAR
  1391.     c: INTEGER;
  1392.     col: CHAR;
  1393.  
  1394.   BEGIN
  1395.     OldHiText := BottomLine; HiText := OldHiText^; BottomLine := SYS.ADR(HiText);
  1396.     IF at+len+2<MaxLen THEN
  1397.       c := 0; col := 5X;
  1398.       WHILE c<at DO
  1399.         IF HiText.text[c]<CHR(17) THEN col := HiText.text[c] END;
  1400.         INC(c);
  1401.       END;
  1402.       HiText.text[at] := CHR(17-ORD(col));
  1403.       c := at; INC(len,at);
  1404.       WHILE c<len DO
  1405.         HiText.text[c+1] := OldHiText.text[c];
  1406.         INC(c);
  1407.       END;
  1408.       HiText.text[c+1] := col;
  1409.       REPEAT
  1410.         HiText.text[c+2] := OldHiText.text[c];
  1411.         INC(c);
  1412.       UNTIL HiText.text[c-1]=0X;
  1413.     END;
  1414.     IF HiText.next#NIL THEN HiText.next.prev := SYS.ADR(HiText) END;
  1415.     IF HiText.prev#NIL THEN HiText.prev.next := SYS.ADR(HiText) END;
  1416.   END HiLite;
  1417.  
  1418.  
  1419.   PROCEDURE UnHiLite();
  1420.  
  1421.   BEGIN
  1422.     IF HiText.next#NIL THEN HiText.next.prev := OldHiText END;
  1423.     IF HiText.prev#NIL THEN HiText.prev.next := OldHiText END;
  1424.   END UnHiLite;
  1425.  
  1426.  
  1427.   PROCEDURE CalcSkipTab;  (* Make skip-table for Boyer-Moore Alg. *)
  1428.   VAR i,j: INTEGER;
  1429.  
  1430.   BEGIN
  1431.     FOR i := 0 TO 255 DO skipTab[i] := flen END;
  1432.     i := 0;
  1433.     FOR j := flen-1 TO 0 BY -1 DO
  1434.       IF skipTab[ORD(FindStr[j])] = flen THEN
  1435.         skipTab[ORD(FindStr[j])] := i;
  1436.       END;
  1437.       INC(i);
  1438.     END;
  1439.   END CalcSkipTab;
  1440.  
  1441.  
  1442.   PROCEDURE Search(): BOOLEAN;
  1443.   (* Searches string and hilites it if found. Result is TRUE if string found *)
  1444.  
  1445.   VAR ch: CHAR;
  1446.       i,j,t: INTEGER;
  1447.  
  1448.   BEGIN
  1449.     IF flen > BottomLine.size THEN RETURN f END;
  1450.     i := flen-1;
  1451.     FOR j := flen-1 TO 0 BY -1 DO
  1452.       LOOP
  1453.         ch := BottomLine.text[i];
  1454.         CASE ch OF "a".."z","à".."ö","ø".."þ": DEC(ch,caseDelta) ELSE END;
  1455.         IF ch = FindStr[j] THEN EXIT END;
  1456.         t := skipTab[ORD(ch)];
  1457.         IF flen-j > t THEN INC(i,flen-j) ELSE INC(i,t) END;
  1458.         IF i >= BottomLine.size THEN RETURN f END;
  1459.         j := flen-1;
  1460.       END;
  1461.       DEC(i);
  1462.     END;
  1463.     INC(i); IF i<0 THEN RETURN f END;
  1464.     SYS.SETREG(0,TryBottomnext());
  1465.     FindLine := BottomLine;
  1466.     HiLite(i,flen);
  1467.     found := w; RETURN w;
  1468.   END Search;
  1469.  
  1470.  
  1471.   PROCEDURE ShowInfo(Fast: BOOLEAN);
  1472.   VAR IStr : String;
  1473.       fmt  : e.LSTRPTR;
  1474.       i    : INTEGER;
  1475.       data : STRUCT name : e.STRPTR;
  1476.                     perc : LONGINT;
  1477.                     tlen : LONGINT;
  1478.                     flen : LONGINT;
  1479.                     lins : LONGINT;
  1480.              END;
  1481.   BEGIN
  1482.     data.name := SYS.ADR(OldName);
  1483.     data.tlen := TextLength;
  1484.     data.flen := FileLength;
  1485.     IF data.flen=0 THEN data.flen := ReadLength END;
  1486.     IF data.flen=0 THEN data.flen := 1 END;
  1487.     data.perc := TextLength * 100 DIV data.flen;
  1488.     data.lins := AnzLines-1;
  1489.     fmt := LocStr(MSGINFOFMT);
  1490.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(IStr));
  1491.     IStr[0] := 7X; IF depth<2 THEN IStr[0] := 2X END;
  1492.     i := SHORT(str.Length(IStr));
  1493.     REPEAT IStr[i] := 20X; INC(i) UNTIL (i>=LEN(IStr)-2) OR (i>=NumColumns+2);
  1494.     IStr[i] := 0X;
  1495.     CopyToWriteText(SYS.ADR(IStr));
  1496.     AddBottomLine(SYS.ADR(writeText),Fast);
  1497.     Info := w;
  1498.     Scroll := f;
  1499.   END ShowInfo;
  1500.  
  1501.  
  1502.   PROCEDURE Help; (* executed when HELP or H is pressed *)
  1503.  
  1504.   CONST
  1505.     num = 25;
  1506.  
  1507.   VAR
  1508.     i,j  : INTEGER;
  1509.     help : ARRAY num OF e.LSTRPTR;
  1510.     fmt  : e.LSTRPTR;
  1511.     data : StringPtr;
  1512.     h1   : String;
  1513.  
  1514.   BEGIN
  1515.     data := SYS.ADR(Version);
  1516.     fmt := LocStr(MSGH1);
  1517.     e.OldRawDoFmt(fmt^,SYS.ADR(data),StuffChar,SYS.ADR(h1));
  1518.     help[ 0] := SYS.ADR(h1);
  1519.     help[ 1] := SYS.ADR("");
  1520.     help[ 2] := LocStr(MSGH2);
  1521.     help[ 3] := LocStr(MSGH3);
  1522.     help[ 4] := LocStr(MSGH4);
  1523.     help[ 5] := LocStr(MSGH5);
  1524.     help[ 6] := LocStr(MSGH6);
  1525.     help[ 7] := LocStr(MSGH7);
  1526.     help[ 8] := LocStr(MSGH8);
  1527.     help[ 9] := LocStr(MSGH9);
  1528.     help[10] := LocStr(MSGH10);
  1529.     help[11] := LocStr(MSGH11);
  1530.     help[12] := LocStr(MSGH12);
  1531.     help[13] := LocStr(MSGH13);
  1532.     help[14] := LocStr(MSGH24);
  1533.     help[15] := LocStr(MSGH14);
  1534.     help[16] := LocStr(MSGH23);
  1535.     help[17] := LocStr(MSGH15);
  1536.     help[18] := LocStr(MSGH16);
  1537.     help[19] := LocStr(MSGH17);
  1538.     help[20] := LocStr(MSGH18);
  1539.     help[21] := SYS.ADR("");
  1540.     help[22] := LocStr(MSGH19);
  1541.     help[23] := LocStr(MSGH21);
  1542.     help[24] := LocStr(MSGH22);
  1543.     ClearDisplay();
  1544.     j := (NumLines - num) DIV 2; IF j<0 THEN j:=0 END;
  1545.     i := 0;
  1546.     WHILE (i<num) & (i+j<NumLines) DO
  1547.       WriteTo(SYS.VAL(StringPtr,help[i]),j+i);
  1548.       INC(i);
  1549.     END;
  1550.     LOOP
  1551.       e.WaitPort(Window.userPort);
  1552.       MyMsgPtr := e.GetMsg(Window.userPort);
  1553.       IF (LONGSET{I.rawKey,I.mouseButtons}*MyMsgPtr.class#LONGSET{}) & (MyMsgPtr.code<128) THEN EXIT END;
  1554.       e.ReplyMsg(MyMsgPtr);
  1555.     END;
  1556.     e.ReplyMsg(MyMsgPtr);
  1557.     BottomLine := TopLine;
  1558.     NewDisplay
  1559.   END Help;
  1560.  
  1561.  
  1562.   PROCEDURE Bottom;  (* executed when END or B is pressed *)
  1563.  
  1564.   BEGIN
  1565.     WaitAllRead;
  1566.     BottomLine := LastLine;
  1567.     NewDisplay
  1568.   END Bottom;
  1569.  
  1570.  
  1571.   PROCEDURE Space(): BOOLEAN;  (* executed if space or LMB is pressed *)
  1572.   (* IF result=w THEN EXIT END *)
  1573.  
  1574.   BEGIN
  1575.     IF (MyFile=NIL) & (BottomLine.next=NIL) THEN        (* End of file? *)
  1576.       IF wasInfo THEN RETURN w END;
  1577.       ShowInfo(Shift);
  1578.     ELSE
  1579.       IF Down THEN
  1580.         Scroll := ~Scroll;
  1581.         IF ~Scroll THEN ShowInfo(Fast) END;
  1582.       ELSE
  1583.         Down := w;
  1584.         Scroll := w;
  1585.       END;
  1586.       Fast := Shift;
  1587.     END;
  1588.     RETURN f;
  1589.   END Space;
  1590.  
  1591.  
  1592.   PROCEDURE BackSpace;  (* executed if backspace or RMB is pressed *)
  1593.  
  1594.   BEGIN
  1595.     Fast := Shift;
  1596.     Scroll := Down OR ~Scroll;
  1597.     Down := f
  1598.   END BackSpace;
  1599.  
  1600.  
  1601. BEGIN
  1602.   (* $IF SmallData *)
  1603.   SYS.SETREG(13,e.AbsExecBase.thisTask.userData);
  1604.   (* $END *)
  1605.  
  1606.   (* $IFNOT ClearVars *)
  1607.   Find[0] := 0X; FindStr[0] := 0X; Goto[0] := 0X;
  1608.   (* $END *)
  1609.  
  1610.   Down := w;
  1611.  
  1612.   IF e.AllocSignal(Window.userPort.sigBit) >= 0 THEN
  1613.     showTaskOk := w;
  1614.     Window.userPort.sigTask := e.FindTask(NIL);
  1615.   END;
  1616.  
  1617.   showSigBit := e.AllocSignal(-1);
  1618.   IF showSigBit >= 0 THEN showSig := LONGSET{showSigBit};
  1619.                      ELSE showTaskOk := f; showSig := LONGSET{} END;
  1620.  
  1621.   e.Signal(Me,mySig);
  1622.  
  1623.   SYS.SETREG(0,e.Wait(showSig));
  1624.  
  1625.   LOOP
  1626.  
  1627.     IF NewDisp THEN NewDisp := f; NewDisplay END;
  1628.  
  1629. (*------  Type Text:  ------*)
  1630.  
  1631.     LOOP
  1632.       IF Scroll THEN
  1633.         IF Down THEN
  1634.           ScrollDown(Fast);
  1635.           Scroll := (MyFile#NIL) OR (BottomLine.next#NIL);
  1636.         ELSE
  1637.           ScrollUp(Fast);
  1638.           Scroll := (TopLine.prev#NIL) & (TopLine.prev.prev#NIL);
  1639.         END;
  1640.       ELSE
  1641.         ScrollDisplay(f,f,w);
  1642.         e.WaitPort(Window.userPort);
  1643.       END;
  1644.  
  1645.       MyMsgPtr := e.GetMsg(Window.userPort);
  1646.  
  1647.       IF MyMsgPtr # NIL THEN
  1648.         IF ~(I.inactiveWindow IN MyMsgPtr.class) THEN EXIT END;
  1649.         e.ReplyMsg(MyMsgPtr);
  1650.         I.OldModifyIDCMP(Window,MyIdcmp-LONGSET{I.mouseButtons});
  1651.         e.WaitPort(Window.userPort);
  1652.         I.OldModifyIDCMP(Window,MyIdcmp);
  1653.       END;
  1654.  
  1655.     END;
  1656.  
  1657.     Code      := MyMsgPtr.code;
  1658.     Class     := MyMsgPtr.class;
  1659.     Qualifier := MyMsgPtr.qualifier;
  1660.  
  1661.     e.ReplyMsg(MyMsgPtr);
  1662.  
  1663.     Shift := {ie.lShift,ie.rShift,ie.capsLock} * Qualifier # {};
  1664.     Alt   := {ie.lAlt  ,ie.rAlt}               * Qualifier # {};
  1665.     Sync  := ~ (ie.control IN Qualifier);
  1666.  
  1667.     IF ~Sync THEN Shift := w END;
  1668.  
  1669.  
  1670.     IF ((I.rawKey       IN Class) & (Code<80H)) OR
  1671.        ((I.mouseButtons IN Class) & ({ie.leftButton,ie.rightButton}*Qualifier#{}))
  1672.     THEN
  1673.       wasInfo := f;
  1674.       IF Info THEN DelLine(Shift); wasInfo := w; END;
  1675.     END;
  1676.  
  1677.  
  1678.     IF I.mouseButtons IN Class THEN
  1679.  
  1680.       IF    (ie.leftButton IN Qualifier)   & Space()   THEN EXIT
  1681.       ELSIF ie.rightButton IN Qualifier THEN BackSpace END;
  1682.  
  1683.     ELSIF I.closeWindow IN Class THEN
  1684.       EXIT;
  1685.  
  1686.     ELSIF (I.newSize IN Class) THEN
  1687.       Scroll := f;
  1688.       zoomed := w;
  1689.       IF Window.height = initialheight THEN
  1690.         zoomed := f;
  1691.         BottomLine := TopLine;
  1692.         NewDisplay;
  1693.       END;
  1694.  
  1695.     ELSIF (I.rawKey IN Class) & (Code<80H) & ~zoomed THEN
  1696.  
  1697.       CASE Code OF
  1698.  
  1699.       | SPACE: IF Space() THEN EXIT END                     (* Space *)
  1700.  
  1701.       | BS:    BackSpace                                    (* BackSpace *)
  1702.  
  1703.       | DOWN,NK2,NK3:                                       (* Down *)
  1704.  
  1705.           IF (MyFile=NIL) & (BottomLine.next=NIL) THEN
  1706.             I.DisplayBeep(NIL)
  1707.           ELSE
  1708.             IF Shift & (Code # NK3) THEN
  1709.               Scroll := ~Down OR ~Scroll OR ~Fast;
  1710.               Fast := w; Down := w;
  1711.             ELSE
  1712.               IF Alt OR (Code=NK3) THEN
  1713.                 IF oldstyle THEN
  1714.                   i := NumLines-1;
  1715.                   REPEAT
  1716.                     ScrollDown(w);
  1717.                     DEC(i);
  1718.                   UNTIL i=0;
  1719.                 ELSE
  1720.                   IF BottomLine.next#NIL THEN BottomLine := BottomLine.next END;
  1721.                   NewDisplay;
  1722.                 END;
  1723.               ELSE
  1724.                 ScrollDown(w);
  1725.               END;
  1726.               Scroll := f;
  1727.             END;
  1728.           END;
  1729.  
  1730.       | UP,NK8,NK9:                                        (* Up *)
  1731.  
  1732.           IF (TopLine.prev=NIL) OR (TopLine.prev.prev=NIL) THEN
  1733.             I.DisplayBeep(NIL)
  1734.           ELSE
  1735.             IF Shift & (Code # NK9) THEN
  1736.               Scroll := Down OR ~Scroll OR ~Fast;
  1737.               Fast := w; Down := f;
  1738.             ELSE
  1739.               IF Alt OR (Code=NK9) THEN
  1740.                 i := NumLines-1;
  1741.                 IF oldstyle THEN
  1742.                   REPEAT
  1743.                     ScrollUp(w);
  1744.                     DEC(i);
  1745.                   UNTIL i=0;
  1746.                 ELSE
  1747.                   (*IF TopLine.prev#NIL THEN*)
  1748.                   BottomLine := TopLine;
  1749.                   WHILE (i>0) & (BottomLine.prev#NIL) DO
  1750.                     BottomLine := BottomLine.prev;
  1751.                     DEC(i);
  1752.                   END;
  1753.                   NewDisplay;
  1754.                   (*END;*)
  1755.                 END;
  1756.               ELSE
  1757.                 ScrollUp(w);
  1758.               END;
  1759.               Scroll := f;
  1760.             END;
  1761.           END;
  1762.  
  1763.       | CR,ENTER: ScrollDown(f); Scroll := f;              (* CR *)
  1764.  
  1765.       | NK7: BottomLine := FirstLine; NewDisplay           (* Home *)
  1766.  
  1767.       | NK1: Bottom                                        (* End *)
  1768.  
  1769.       | F1..F10:                                           (* F1..F10 *)
  1770.  
  1771.           i := Code-F1;
  1772.           IF ~ Shift & (TextMarkers[i]#NIL) THEN
  1773.             BottomLine := TextMarkers[i];
  1774.             NewDisplay;
  1775.           ELSE
  1776.             TextMarkers[i] := TopLine;
  1777.           END
  1778.  
  1779.       | NK0:  IF ~wasInfo THEN ShowInfo(Shift) END;        (* NK 0 *)
  1780.  
  1781.       | HELP: Help                                         (* Help *)
  1782.  
  1783.       | ESC:  EXIT                                         (* Quit *)
  1784.  
  1785.       | NK5:  IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift)END; (* safe Quit *)
  1786.  
  1787.       ELSE
  1788.  
  1789.         IF Code<40H THEN         (* examine vanilla keycode: *)
  1790.  
  1791.           chr := KeyMap[Code];
  1792.  
  1793.           CASE chr OF
  1794.  
  1795.           | "t": BottomLine := FirstLine; NewDisplay       (* Home *)
  1796.  
  1797.           | "b": Bottom;                                   (* End *)
  1798.  
  1799.           | "s","f","n","p":                               (* Find, Next, Previous *)
  1800.  
  1801.             IF (chr="f") OR (chr="s") THEN
  1802.               caseDelta := 32; IF Shift THEN caseDelta := 0 END;
  1803.               GetString(Find,f,w,f);
  1804.               FindLine := NIL; flen := 0;
  1805.               LOOP
  1806.                 FindStr[flen] := Find[flen];
  1807.                 CASE FindStr[flen] OF
  1808.                   "a".."z","à".."ö","ø".."þ": DEC(FindStr[flen],caseDelta) |
  1809.                   0X: EXIT;
  1810.                 ELSE
  1811.                 END;
  1812.                 INC(flen);
  1813.               END;
  1814.               CalcSkipTab;
  1815.             END;
  1816.             found := f;
  1817.             IF FindStr # "" THEN
  1818.               Busy;
  1819.               i := NumLines;
  1820.               IF FindLine # NIL THEN FindLine := FindLine.next END;
  1821.               WHILE (i>0) & (BottomLine#NIL) & (BottomLine#FindLine) DO
  1822.                 BottomLine := BottomLine.prev; DEC(i);
  1823.               END;
  1824.               IF (BottomLine # FindLine) OR (BottomLine=NIL) THEN
  1825.                 BottomLine := TopLine
  1826.               END;
  1827.               IF chr # "p" THEN                          (* next *)
  1828.                 WHILE (BottomLine # NIL) & ~ Search() DO
  1829.                   SYS.SETREG(0,TryBottomnext());
  1830.                   BottomLine := BottomLine.next;
  1831.                 END;
  1832.               ELSE                                       (* previous *)
  1833.                 IF BottomLine.prev#NIL THEN BottomLine:=BottomLine.prev END;
  1834.                 REPEAT
  1835.                   BottomLine := BottomLine.prev
  1836.                 UNTIL (BottomLine=NIL) OR Search();
  1837.               END;
  1838.               IF BottomLine#NIL THEN
  1839.                 li := NumLines DIV 2;
  1840.                 WHILE (li>0) & (BottomLine.prev#NIL) DO BottomLine := BottomLine.prev; DEC(li) END;
  1841.               END;
  1842.               UnBusy;
  1843.             END;
  1844.  
  1845.             IF ~ found THEN
  1846.               I.DisplayBeep(NIL);
  1847.               BottomLine := TopLine;
  1848.             END;
  1849.             NewDisplay;
  1850.             IF found THEN UnHiLite END;
  1851.  
  1852.           | "w","c":                                       (* write block *)
  1853.             IF (TextMarkers[0]#NIL) & (TextMarkers[1]#NIL) & ~print & ~save THEN
  1854.               savefrom := 0; savesize := 0;
  1855.               l := TextMarkers[0].prev; WHILE l.prev#NIL DO l := l.prev; INC(savefrom,l.len) END;
  1856.               l := TextMarkers[1].prev; WHILE l#NIL DO INC(savesize,l.len); l := l.prev END;
  1857.               l := TextMarkers[1]; i := NumLines; WHILE (i>1) & (l#NIL) DO DEC(i); INC(savesize,LONG(l.len)); l := l.next END;
  1858.               DEC(savesize,savefrom);
  1859.               IF savesize>0 THEN
  1860.                 IF chr="c" THEN copy := w ELSE
  1861.                   GetString(WriteName,f,w,f);
  1862.                   copy := f;
  1863.                 END;
  1864.                 WaitAllRead; save := w; e.Signal(Me,mySig);
  1865.               END
  1866.             END
  1867.  
  1868.           | "o","e":                                       (* Print, Edit *)
  1869.  
  1870.             IF Shift & Alt & ~print & ~save THEN
  1871.               nameptr := SYS.ADR(Name);
  1872.               IF chr="o" THEN
  1873.                 e.OldRawDoFmt('Type "%s" to PRT:',SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1874.               ELSE
  1875.                 e.OldRawDoFmt(editcmd,SYS.ADR(nameptr),StuffChar,SYS.ADR(PStr));
  1876.               END;
  1877.               WaitAllRead; print := w; e.Signal(Me,mySig);
  1878.             END
  1879.  
  1880.           | "l":                                           (* Load Text *)
  1881.  
  1882.             ClearDisplay;
  1883.             NewText := w; e.Signal(Me,mySig);
  1884.             REPEAT UNTIL (showSigBit IN e.Wait(showSig)) & ~ NewText |
  1885.  
  1886.           | "g":                                           (* goto *)
  1887.  
  1888.             GetString(Goto,w,w,f);
  1889.             li := SHORT(StrInfo.longInt);
  1890.             Busy;
  1891.             BottomLine := FirstLine;
  1892.             WHILE (li >= 0) & TryBottomnext() DO
  1893.               BottomLine := BottomLine.next;
  1894.               DEC(li)
  1895.             END;
  1896.             UnBusy;
  1897.             NewDisplay
  1898.  
  1899.           | "h":     Help                                  (* Help *)
  1900.  
  1901.           | "q","x": IF wasInfo OR fastquit THEN EXIT ELSE ShowInfo(Shift) END; (* safe Quit *)
  1902.  
  1903.           ELSE END;
  1904.  
  1905.         END;   (* IF Code<40H THEN *)
  1906.  
  1907.       END;   (* CASE Code OF *)
  1908.  
  1909.     END;   (* IF I.rawKey IN Class THEN *)
  1910.  
  1911.   END;   (* LOOP *)
  1912.  
  1913.   Done := w;
  1914.   e.Signal(Me,mySig);
  1915.   LOOP SYS.SETREG(0,e.Wait(LONGSET{})) END;
  1916.  
  1917. END ShowProc;
  1918.  
  1919. (* $Debug= *)
  1920.  
  1921.  
  1922. (*--------------------------  File Requester:  ----------------------------*)
  1923.  
  1924.  
  1925. PROCEDURE FileReq(VAR Name: String): BOOLEAN;
  1926.  
  1927. VAR
  1928.   fr: FileRequesterPtr;
  1929.   pub,scr: I.ScreenPtr;
  1930.   i,j: INTEGER;
  1931.   res: BOOLEAN;
  1932.   screenTag: LONGINT;
  1933.  
  1934. BEGIN
  1935.   j := SHORT(str.Length(Name));
  1936.   WHILE (j>0) & (Name[j]#":") & (Name[j]#"/") DO DEC(j) END;
  1937.   IF j=0 THEN j := -1 END;
  1938.   i := 0;
  1939.   WHILE i<=j DO Dirname[i] := Name[i]; INC(i) END; Dirname[i] := 0X;
  1940.   j := 0;
  1941.   REPEAT Filename[j] := Name[i]; INC(j); INC(i) UNTIL Name[i-1]=0X;
  1942.  
  1943.   IF asl=NIL THEN
  1944.     asl := e.OpenLibrary("asl.library",36);
  1945.     IF asl=NIL THEN Error("Can't open asl.library") END;
  1946.   END;
  1947.  
  1948.   IF (Window # NIL) & (asl.version >= 38) THEN
  1949.     screenTag := screen;
  1950.     scr := Window.wScreen;
  1951.   ELSE
  1952.     screenTag := u.ignore;
  1953.     scr := NIL;
  1954.     pub := I.LockPubScreen(NIL);
  1955.     IF pub # NIL THEN
  1956.       I.ScreenToFront(pub);
  1957.       I.UnlockPubScreen(NIL,pub);
  1958.     END;
  1959.   END;
  1960.  
  1961.   fr := AllocAslRequestTags(fileRequest,
  1962.                             screenTag,scr,
  1963.                             taghail, SYS.ADR(MuchText),
  1964.                             file,    SYS.ADR(Filename),
  1965.                             dir,     SYS.ADR(Dirname),
  1966.                             pattern, SYS.ADR(Pattern),
  1967.                             funcFlags,ASH(1,patGad),
  1968.                             tagWidth, frwidth,
  1969.                             tagHeight,frheight,
  1970.                             u.done);
  1971.   IF fr=NIL THEN Error(LocStr(MSGOOM)^) END;
  1972.  
  1973.   res := AslRequestTags(fr,u.done);
  1974.  
  1975.   IF res THEN
  1976.     COPY(fr.file^,Filename);
  1977.     COPY(fr.dir^,Dirname);
  1978.   END;
  1979.  
  1980.   frwidth  := fr.width;
  1981.   frheight := fr.height;
  1982.   COPY(fr.pat^,Pattern);
  1983.  
  1984.   FreeAslRequest(fr);
  1985.   IF ~res THEN RETURN f END;
  1986.  
  1987.   Name := Dirname;
  1988.   i := SHORT(str.Length(Name));
  1989.   IF (i>0) THEN
  1990.     CASE Name[i-1] OF "/",":": ELSE
  1991.       Name[i] := "/"; INC(i);
  1992.     END;
  1993.   END;
  1994.   j := 0;
  1995.   LOOP
  1996.     Name[i] := Filename[j];
  1997.     IF (Name[i]=0X) OR (i=255) THEN EXIT END;
  1998.     INC(i);
  1999.     INC(j);
  2000.   END;
  2001.   Name[i] := 0X;
  2002.   IF Window # NIL THEN
  2003.     I.ScreenToFront(Window.wScreen);
  2004.     I.ActivateWindow(Window);
  2005.   END;
  2006.   RETURN w
  2007. END FileReq;
  2008.  
  2009.  
  2010. (*--------------------------  Decrunch:  ----------------------------*)
  2011.  
  2012.  
  2013. PROCEDURE Exists(name: ARRAY OF CHAR): BOOLEAN; (* $CopyArrays- *)
  2014. VAR lock: d.FileLockPtr;
  2015.     result: BOOLEAN;
  2016.     oldwp: e.APTR;
  2017. BEGIN
  2018.   result := f;
  2019.   oldwp := Me.windowPtr;
  2020.   Me.windowPtr := -1;
  2021.   lock := d.Lock(name,d.sharedLock);
  2022.   IF lock # NIL THEN
  2023.     result := w;
  2024.     d.UnLock(lock)
  2025.   END;
  2026.   Me.windowPtr := oldwp;
  2027.   RETURN result
  2028. END Exists;
  2029.  
  2030.  
  2031. PROCEDURE Decrunch;
  2032.  
  2033. CONST
  2034.   tagBase    = u.user + ORD("X")*256 + ORD("P");
  2035.   inName     = tagBase+01H;
  2036.   inFH       = tagBase+02H;
  2037.   outName    = tagBase+10H;
  2038.   password   = tagBase+24H;
  2039.   getError   = tagBase+25H;
  2040.   shortError = tagBase+31H;
  2041.   typePacked = 1;
  2042.   flagsPassword = 0;
  2043.  
  2044. TYPE
  2045.   XpkFib = STRUCT
  2046.     type       : LONGINT;    (* Unpacked, packed, archive? *)
  2047.     uLen       : LONGINT;
  2048.     cLen       : LONGINT;
  2049.     nLen       : LONGINT;
  2050.     uCur       : LONGINT;
  2051.     cCur       : LONGINT;
  2052.     id         : LONGINT;
  2053.     packer     : ARRAY 6 OF CHAR;
  2054.     subVersion : INTEGER;
  2055.     masVersion : INTEGER;
  2056.     flags      : LONGSET;
  2057.     head       : ARRAY 16 OF CHAR;
  2058.     ratio      : LONGINT;
  2059.     reserved   : ARRAY 8 OF LONGINT;
  2060.   END;
  2061.  
  2062. VAR
  2063.   file: d.FileHandlePtr;
  2064.   err: LONGINT;
  2065.   xpkFib: XpkFib;
  2066.   Buf: ARRAY 100 OF CHAR;
  2067.   len,i: LONGINT;
  2068.   ch: CHAR;
  2069.  
  2070.   PROCEDURE ExamineTags {xpk,-36}(VAR fib{8}  : XpkFib;
  2071.                                   tag1{9}..   : e.APTR): LONGINT;
  2072.   PROCEDURE UnpackTags  {xpk,-48}(tag1{8}..   : e.APTR): LONGINT;
  2073.  
  2074. BEGIN
  2075.   Decrunched := f;
  2076.   OldName := Name;
  2077.  
  2078.   IF stdin THEN RETURN END;
  2079.   IF Exists("T:") THEN Name := "T:" ELSE Name := "RAM:" END;
  2080.  
  2081.   e.OldRawDoFmt("Decrunched.%lx",SYS.ADR(meInt),StuffChar,SYS.ADR(Name[str.Length(Name)]));
  2082.  
  2083.   IF xpk=NIL THEN xpk := e.OpenLibrary("xpkmaster.library",1) END;
  2084.  
  2085.   LOOP
  2086.     IF xpk # NIL THEN
  2087.       err := ExamineTags(xpkFib,inFH,SYS.VAL(LONGINT,MyFile),u.done);
  2088.       IF (err#0) & (err#-20) THEN
  2089.         Error(LocStr(MSGOOM)^)
  2090.       END;
  2091.       IF (err=-20) OR (xpkFib.type#typePacked) THEN
  2092.         Name := OldName;
  2093.         EXIT
  2094.       END;
  2095.       IF flagsPassword IN xpkFib.flags THEN GetString(Password,f,f,w) END;
  2096.       Busy;
  2097.       err := UnpackTags(inFH,       SYS.VAL(LONGINT,MyFile),
  2098.                         outName,    SYS.ADR(Name),
  2099.                         password,   SYS.ADR(Password),
  2100.                         getError,   SYS.ADR(Buf),
  2101.                         shortError, e.true,
  2102.                         u.done);
  2103.       UnBusy;
  2104.       IF err#0 THEN Error(Buf) END;
  2105.       file := d.Open(Name,d.oldFile);
  2106.       IF file#NIL THEN
  2107.         Decrunched := w;
  2108.         d.OldClose(MyFile);
  2109.         MyFile := file;
  2110.         EXIT
  2111.       ELSE
  2112.         Error(LocStr(MSGCOF)^);
  2113.       END;
  2114.     END;
  2115.     Name := OldName;
  2116.     EXIT
  2117.   END;
  2118. END Decrunch;
  2119.  
  2120.  
  2121. (*-----------------  Screen Mode Requester:  ------------------------*)
  2122.  
  2123.  
  2124. PROCEDURE ScreenModeReq (VAR displayID : LONGINT): BOOLEAN;
  2125.  
  2126. VAR
  2127.   smReq: ScreenModeRequesterPtr;
  2128.   ok: BOOLEAN;
  2129.   initID: LONGINT;
  2130.  
  2131. BEGIN
  2132.   initID := displayID;
  2133.   IF initID = g.invalidID THEN initID := 0 END;
  2134.  
  2135.   IF asl=NIL THEN
  2136.     asl := e.OpenLibrary("asl.library",36);
  2137.     IF asl=NIL THEN Error("Can't open asl.library") END;
  2138.   END;
  2139.  
  2140.   IF asl.version < 38 THEN Error("asl v38 required") END;
  2141.  
  2142.   smReq := AllocAslRequestTags(screenModeRequest,u.done);
  2143.   IF smReq=NIL THEN RETURN f END;
  2144.  
  2145.   ok := AslRequestTags(smReq,
  2146.                        initialDisplayID , initID,
  2147.                        smPropertyFlags  , LONGSET{g.isWB},
  2148.                        smPropertyMask   , LONGSET{g.isWB},
  2149.                        u.done);
  2150.   IF ok THEN displayID := smReq.displayID END;
  2151.   FreeAslRequest(smReq);
  2152.   RETURN ok;
  2153. END ScreenModeReq;
  2154.  
  2155.  
  2156. (*-------------------------------------------------------------------------*)
  2157.  
  2158.  
  2159. PROCEDURE SavePrefs(save: BOOLEAN);
  2160.  
  2161.   PROCEDURE SavePrefsName(name: StringPtr);
  2162.   VAR file: d.FileHandlePtr;
  2163.       l: LONGINT;
  2164.   BEGIN
  2165.     file := d.Open(name^,d.newFile);
  2166.     IF file # NIL THEN
  2167.       SYS.SETREG(0,d.Write(file,"FORM",4));
  2168.       l := 16;
  2169.       SYS.SETREG(0,d.Write(file,l,4));
  2170.       SYS.SETREG(0,d.Write(file,"MUMO",4));
  2171.       SYS.SETREG(0,d.Write(file,"DPID",4));
  2172.       l := 4;
  2173.       SYS.SETREG(0,d.Write(file,l,4));
  2174.       SYS.SETREG(0,d.Write(file,id,4));
  2175.       d.OldClose(file);
  2176.     END;
  2177.   END SavePrefsName;
  2178.  
  2179. BEGIN
  2180.   SavePrefsName(SYS.ADR("ENV:MuchMore.prefs"));
  2181.   IF save THEN
  2182.     SavePrefsName(SYS.ADR("ENVARC:MuchMore.prefs"))
  2183.   END;
  2184. END SavePrefs;
  2185.  
  2186.  
  2187. (*-------------------------------------------------------------------------*)
  2188.  
  2189.  
  2190. PROCEDURE LoadPrefs;
  2191.  
  2192. VAR file: d.FileHandlePtr;
  2193.     l,i,s: LONGINT;
  2194.     buf: ARRAY 80 OF CHAR;
  2195.     ok: BOOLEAN;
  2196.  
  2197. BEGIN
  2198.   file := NIL;
  2199.   IF Exists("PROGDIR:") THEN
  2200.     file := d.Open("PROGDIR:MuchMore.prefs",d.oldFile);
  2201.   END;
  2202.   IF (file=NIL) & Exists("ENV:") THEN
  2203.     file := d.Open("ENV:MuchMore.prefs",d.oldFile);
  2204.   END;
  2205.   IF file # NIL THEN
  2206.     LOOP
  2207.       IF (d.Read(file,i,4) <= 0)        OR
  2208.          (i # SYS.VAL(LONGINT,"FORM"))  OR
  2209.          (d.Read(file,s,4) <= 0)        OR
  2210.          (d.Read(file,i,4) <= 0)        OR
  2211.          (i # SYS.VAL(LONGINT,"MUMO"))    THEN EXIT END;
  2212.       WHILE w DO
  2213.         IF (d.Read(file,i,4) <= 0)      OR
  2214.            (d.Read(file,s,4) <= 0)        THEN EXIT END;
  2215.         IF ODD(s) THEN INC(s) END;
  2216.         IF (s=4) & (i=SYS.VAL(LONGINT,"DPID")) THEN
  2217.           SYS.SETREG(0,d.Read(file,id,4));
  2218.         ELSE
  2219.           IF s < 0 THEN EXIT END;
  2220.           SYS.SETREG(0,d.Seek(file,s,d.current));
  2221.         END;
  2222.       END;
  2223.  
  2224.       EXIT;
  2225.     END;
  2226.     d.OldClose(file);
  2227.   END;
  2228.   IF (d.GetVar("EDITOR",buf,SIZE(buf),LONGSET{})>0) THEN
  2229.     COPY(buf,editcmd);
  2230.   END;
  2231. END LoadPrefs;
  2232.  
  2233.  
  2234. (*------------------------  Get Tooltypes:  --------------------------*)
  2235.  
  2236.  
  2237. PROCEDURE ParseIcon(icon: DiskObjectPtr);
  2238. VAR tt: StringPtr;
  2239.  
  2240. BEGIN
  2241.   IF icon # NIL THEN
  2242.     tt := FindToolType(icon.toolTypes,"PALETTE");    IF (tt # NIL) THEN COPY(tt^,Pens) END;
  2243.     tt := FindToolType(icon.toolTypes,"EXTRASPACE"); IF (tt # NIL) THEN spacing := SHORT(StrToInt(tt,10)) END;
  2244.     tt := FindToolType(icon.toolTypes,"FONT");       IF (tt # NIL) THEN COPY(tt^,FontName) END;
  2245.     tt := FindToolType(icon.toolTypes,"EDITOR");     IF (tt # NIL) THEN COPY(tt^,editcmd) END;
  2246.     tt := FindToolType(icon.toolTypes,"OLDSTYLE");   IF (tt # NIL) THEN oldstyle := ~MatchToolValue(tt^,"FALSE") END;
  2247.     tt := FindToolType(icon.toolTypes,"FASTQUIT");   IF (tt # NIL) THEN fastquit := ~MatchToolValue(tt^,"FALSE") END;
  2248.     tt := FindToolType(icon.toolTypes,"INTERLEAVED");IF (tt # NIL) THEN interleaved := ~MatchToolValue(tt^,"FALSE") END;
  2249.     tt := FindToolType(icon.toolTypes,"PLANES");     IF (tt # NIL) THEN depth := SHORT(StrToInt(tt,10)) END;
  2250.     tt := FindToolType(icon.toolTypes,"TABWIDTH");   IF (tt # NIL) THEN tabw := SHORT(StrToInt(tt,10)) END;
  2251.     tt := FindToolType(icon.toolTypes,"PUBSCREEN");  IF (tt # NIL) THEN COPY(tt^,pubscreenname) END;
  2252.     tt := FindToolType(icon.toolTypes,"TOOLPRI");    IF (tt # NIL) THEN taskpri := SHORT(SHORT(StrToInt(tt,10))) END;
  2253.     tt := FindToolType(icon.toolTypes,"SCROLLMODE"); IF (tt # NIL) THEN scrollmode := SHORT(StrToInt(tt,10)) END;
  2254.     tt := FindToolType(icon.toolTypes,"LEFTEDGE");   IF (tt # NIL) THEN left  := SHORT(StrToInt(tt,10)) END;
  2255.     tt := FindToolType(icon.toolTypes,"TOPEDGE");    IF (tt # NIL) THEN top   := SHORT(StrToInt(tt,10)) END;
  2256.     tt := FindToolType(icon.toolTypes,"WIDTH");      IF (tt # NIL) THEN width := SHORT(StrToInt(tt,10)) END;
  2257.     tt := FindToolType(icon.toolTypes,"HEIGHT");     IF (tt # NIL) THEN height:= SHORT(StrToInt(tt,10)) END;
  2258.     tt := FindToolType(icon.toolTypes,"WINDOW");     IF (tt # NIL) THEN win := (MatchToolValue(tt^,"TRUE")) END;
  2259.     tt := FindToolType(icon.toolTypes,"FRWIDTH");    IF (tt # NIL) THEN frwidth := SHORT(StrToInt(tt,10)) END;
  2260.     tt := FindToolType(icon.toolTypes,"FRHEIGHT");   IF (tt # NIL) THEN frheight := SHORT(StrToInt(tt,10)) END;
  2261.     FreeDiskObject(icon);
  2262.   END;
  2263. END ParseIcon;
  2264.  
  2265.  
  2266. (*------------------------------  MAIN:  ----------------------------------*)
  2267.  
  2268. BEGIN
  2269.  
  2270. (*------  Init:  ------*)
  2271.  
  2272.   mySigBit := -1;
  2273.   Me := SYS.VAL(d.ProcessPtr,ol.Me);
  2274.   meInt := SYS.VAL(LONGINT,Me);
  2275.   OldDir := Me.currentDir;
  2276.   oldpri := Me.task.node.pri; taskpri := oldpri;
  2277.   WriteName := "PRT:";
  2278.   MemIndex := ChunkSize;
  2279.   Sync := w;
  2280.   FontSize := 8;
  2281.   Pattern := "~(#?.(info|backdrop))";
  2282.   editcmd := 'C:Ed';
  2283.   id := g.invalidID;
  2284.   tabw := 8;
  2285.   depth := 2;
  2286.   left   := 0;
  2287.   top    := 0;
  2288.   width  := 640;
  2289.   height := 200;
  2290.   frwidth:= 300;
  2291.   frheight := 200;
  2292.   scrollmode := 1;
  2293.  
  2294.   IF (I.base.libNode.version < 37) OR (g.base.libNode.version < 37) THEN
  2295.     IF I.DisplayAlert(0,"\x00\x64\x14Need OS2 or higher!\o",50) THEN END;
  2296.     HALT(d.fail);
  2297.   END;
  2298.  
  2299.   mySigBit := e.AllocSignal(-1);
  2300.   IF mySigBit<0 THEN HALT(d.fail) END;
  2301.   mySig := LONGSET{mySigBit};
  2302.  
  2303.   iconBase := e.OpenLibrary("icon.library",0);
  2304.  
  2305.   IF loc.base # NIL THEN
  2306.     catalog := loc.OpenCatalog(NIL,"muchmore.catalog",u.end);
  2307.   END;
  2308.  
  2309.   ol.OutOfMemHandler := OutOfMemHandler;
  2310.  
  2311.   INCL(ol.MemReqs,e.public);
  2312.  
  2313.   ol.New(ShowStack,ShowStackSize);
  2314.   NEW(ShowTask);
  2315.   NEW(FileInfo);
  2316.   NEW(ievent);
  2317.   NEW(conreq);
  2318.   NEW(Buffer);
  2319.  
  2320.   INCL(ol.MemReqs,e.chip);
  2321.   NEW(busyPointer);
  2322.   e.CopyMem(TheBusyPointer,busyPointer^,SIZE(busyPointer^));
  2323.   EXCL(ol.MemReqs,e.chip);
  2324.  
  2325. (*------  Setup:  ------*)
  2326.  
  2327.   NEW(FirstLine);
  2328. (*FirstLine.size := 0;
  2329.   FirstLine.text[0] := 0X; *)
  2330.  
  2331. (*------  Start:  ------*)
  2332.  
  2333.   LoadPrefs;
  2334.  
  2335.   IF ol.wbStarted THEN
  2336.  
  2337.     wbm := ol.wbenchMsg;
  2338.     IF iconBase # NIL THEN
  2339.       j := SHORT(wbm.numArgs); IF j>2 THEN j := 2 END;
  2340.       FOR i := 0 TO j-1 DO
  2341.         SYS.SETREG(0,d.CurrentDir(wbm.argList[i].lock));
  2342.         nameptr := wbm.argList[i].name;
  2343.         icon := GetDiskObject(nameptr^);
  2344.         IF icon=NIL THEN
  2345.           IF d.base.lib.version >= 37 THEN
  2346.             SYS.SETREG(0,d.CurrentDir(d.GetProgramDir()));
  2347.             icon := GetDiskObject(nameptr^);
  2348.           END;
  2349.           IF icon=NIL THEN
  2350.             clock := d.Lock("C:",d.sharedLock);
  2351.             SYS.SETREG(0,d.CurrentDir(clock));
  2352.             icon := GetDiskObject(nameptr^);
  2353.           END;
  2354.         END;
  2355.         ParseIcon(icon);
  2356.       END;
  2357.     END; (* IF iconBase#NIL *)
  2358.  
  2359.     IF wbm.numArgs >= 2 THEN
  2360.       ArgPtr := wbm.argList^[1].name;
  2361.       Name := ArgPtr^;
  2362.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[1].lock));
  2363.     ELSE
  2364.       SYS.SETREG(0,d.CurrentDir(wbm.argList^[0].lock));
  2365.     END;
  2366.     IF clock # NIL THEN d.UnLock(clock) END;
  2367.  
  2368.   ELSE (* CLI started *)
  2369.  
  2370.     stdin := (Me.cis # Me.cli.standardInput); (* Input redirected? *)
  2371.  
  2372.     IF iconBase # NIL THEN
  2373.       progdir := d.GetProgramDir();
  2374.       IF progdir = NIL THEN
  2375.         progdir := d.Lock("C:",d.sharedLock); cLocked := w;
  2376.       END;
  2377.       oldcd := d.CurrentDir(progdir);
  2378.       IF d.GetProgramName(Name,LEN(Name)) THEN
  2379.         nameptr := SYS.VAL(e.APTR,d.FilePart(Name));
  2380.         icon := GetDiskObject(nameptr^);
  2381.         ParseIcon(icon);
  2382.         Name[0] := 0X;
  2383.       END;
  2384.       oldcd := d.CurrentDir(oldcd);
  2385.       IF cLocked THEN d.UnLock(progdir) END;
  2386.     END;
  2387.  
  2388.     rd := d.ReadArgs("B=PLANES/N/K,C=PALETTE/K,D=DISPMODEREQ/S,E=EDITOR/K,F=FONT/K,I=INTERLEAVED/S,O=OLDSTYLE/S,P=TOOLPRI/N/K,Q=FASTQUIT/S,S=SCROLLMODE/N/K,T=TABWIDTH/N/K,U=PUBSCREEN/K,X=EXTRASPACE/N/K,W=WINDOW/S,WL=LEFTEDGE/N/K,WT=TOPEDGE/N/K,WW=WIDTH/N/K,WH=HEIGHT/N/K,FW=FRWIDTH/N/K,FH=FRHEIGHT/N/K,FILE",args,NIL);
  2389.     IF rd=NIL THEN
  2390.       SYS.SETREG(0,d.PrintFault(d.IoErr(),NIL));
  2391.       HALT(d.warn)
  2392.     END;
  2393.     IF args.b # NIL THEN depth := SHORT(args.b^) END;
  2394.     IF args.c # NIL THEN COPY(args.c^,Pens) END;
  2395.     IF args.d # NIL THEN modeReq := w END;
  2396.     IF args.e # NIL THEN COPY(args.e^,editcmd) END;
  2397.     IF args.f # NIL THEN COPY(args.f^,FontName) END;
  2398.     IF args.i # NIL THEN interleaved := w END;
  2399.     IF args.o # NIL THEN oldstyle := w END;
  2400.     IF args.q # NIL THEN fastquit := w END;
  2401.     IF args.p # NIL THEN taskpri := SHORT(SHORT(args.p^)) END;
  2402.     IF args.s # NIL THEN scrollmode := SHORT(args.s^) END;
  2403.     IF args.t # NIL THEN tabw := SHORT(args.t^) END;
  2404.     IF args.u # NIL THEN COPY(args.u^,pubscreenname) END;
  2405.     IF args.x # NIL THEN spacing := SHORT(args.x^) END;
  2406.     IF args.w # NIL THEN win := w END;
  2407.  
  2408.     IF args.wl # NIL THEN left  := SHORT(args.wl^) END;
  2409.     IF args.wt # NIL THEN top   := SHORT(args.wt^) END;
  2410.     IF args.ww # NIL THEN width := SHORT(args.ww^) END;
  2411.     IF args.wh # NIL THEN height:= SHORT(args.wh^) END;
  2412.  
  2413.     IF args.fw # NIL THEN frwidth := SHORT(args.fw^) END;
  2414.     IF args.fh # NIL THEN frheight:= SHORT(args.fh^) END;
  2415.  
  2416.     IF args.file # NIL THEN COPY(args.file^,Name); stdin := f END;
  2417.     d.FreeArgs(rd); rd := NIL;
  2418.   END;
  2419.  
  2420.   IF pubscreenname # "" THEN
  2421.     win := w;
  2422.   END;
  2423.  
  2424.   IF taskpri # oldpri THEN SYS.SETREG(0,e.SetTaskPri(Me,taskpri)) END;
  2425.  
  2426.   IF tabw < 1 THEN tabw := 1 END;
  2427.  
  2428.   IF depth < 1 THEN depth := 1 END;
  2429.   IF depth > 2 THEN depth := 2 END;
  2430.  
  2431.   IF str.Occurs(editcmd,"%s")<0 THEN str.Append(editcmd,' "%s"') END;
  2432.  
  2433.   IF FontName # "" THEN
  2434.     i := 0;
  2435.     j := SHORT(str.Length(FontName));
  2436.     LOOP
  2437.       IF i >= j THEN EXIT END;
  2438.       IF FontName[i]='/' THEN
  2439.         FontName[i] := 0X;
  2440.         FontSize := SHORT(StrToInt(SYS.ADR(FontName[i+1]),10));
  2441.         j := i;
  2442.         EXIT
  2443.       END;
  2444.       INC(i);
  2445.     END;
  2446.     IF j<LEN(FontName)-6 THEN
  2447.       e.CopyMem(".font",FontName[j],6);
  2448.     END;
  2449.   END;
  2450.  
  2451.   IF Pens # "" THEN
  2452.     ci := 0;
  2453.     chptr := SYS.ADR(Pens);
  2454.     Pens[LEN(Pens)-1] := 0X;
  2455.     LOOP
  2456.       Cols[ci] := SHORT(StrToInt(SYS.VAL(StringPtr,chptr),16));
  2457.       INC(ci); IF ci=4 THEN EXIT END;
  2458.       WHILE (chptr^#0X) & (chptr^#",") DO
  2459.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2460.       END;
  2461.       IF chptr^="," THEN
  2462.         chptr:=SYS.VAL(e.APTR,SYS.VAL(LONGINT,chptr)+1)
  2463.       ELSE
  2464.         EXIT
  2465.       END;
  2466.     END;
  2467.   END;
  2468.  
  2469.   IF FontSize>50 THEN FontSize := 50 END;
  2470.   IF FontSize< 5 THEN FontSize :=  5 END;
  2471.  
  2472.   IF spacing< 0 THEN spacing :=  0 END;
  2473.   IF spacing>20 THEN spacing := 20 END;
  2474.  
  2475.   IF width <150 THEN width  := 150 END;
  2476.   IF height< 70 THEN height :=  70 END;
  2477.  
  2478.   IF modeReq THEN
  2479.     IF ScreenModeReq(id) THEN
  2480.       SavePrefs(w);
  2481.     END;
  2482.   END;
  2483.  
  2484. (*------  Open File:  ------*)
  2485.  
  2486.   IF stdin THEN
  2487.     MyFile := d.Input();
  2488.     Name := "STDIN";
  2489.   ELSE
  2490.     LOOP
  2491.       MyFile := d.Open(Name,d.oldFile);
  2492.       IF MyFile#NIL THEN EXIT END;
  2493.       IF ~FileReq(Name) THEN HALT(d.ok) END;
  2494.     END;
  2495.   END;
  2496.  
  2497. (*------  Open Screen:  ------*)
  2498.  
  2499.   IF ~win THEN
  2500.  
  2501.     LOOP
  2502.   
  2503.       IF id=g.invalidID THEN
  2504.         id := g.defaultMonitorID;
  2505.         pub := I.LockPubScreen(NIL);
  2506.         IF pub # NIL THEN
  2507.           id := g.GetVPModeID(SYS.ADR(pub.viewPort));
  2508.           I.UnlockPubScreen(NIL,pub);
  2509.         END;
  2510.       END;
  2511.   
  2512.       IF g.GetDisplayInfoData(NIL,dims,SIZE(dims),g.dtagDims,id) > 0 THEN
  2513.         width  := dims.txtOScan.maxX - dims.txtOScan.minX + 1;
  2514.         height := dims.txtOScan.maxY - dims.txtOScan.minY + 1;
  2515.   
  2516.         IF g.GetDisplayInfoData(NIL,disp,SIZE(disp),g.dtagDisp,id) > 0 THEN
  2517.           lace := g.isLace IN disp.propertyFlags;
  2518.           Scrollable := (g.isDraggable IN disp.propertyFlags) & (scrollmode # 3);
  2519.           IF Scrollable THEN INC(height,height) END;
  2520.   
  2521.           Screen := I.OpenScreenTagsA(NIL,
  2522.                                      I.saLeft,       0,
  2523.                                      I.saTop,        0,
  2524.                                      I.saWidth,      width,
  2525.                                      I.saHeight,     height,
  2526.                                      I.saDepth,      depth,
  2527.                                      I.saDisplayID,  id,
  2528.                                      I.saInterleaved,SYS.VAL(SHORTINT,interleaved),
  2529.                                      I.saOverscan,   I.oScanText,
  2530.                                      I.saPens,       SYS.ADR("\xFF\xFF"),
  2531.                                      I.saQuiet,      I.LTRUE,
  2532.                                      u.done);
  2533.         END;
  2534.       END;
  2535.   
  2536.       IF Screen # NIL THEN EXIT END;
  2537.   
  2538.       DEC(depth);
  2539.       IF depth=0 THEN Error(LocStr(MSGCOS)^) END;
  2540.     END;
  2541.   
  2542.     rp := SYS.ADR(Screen.rastPort);
  2543.     BM := rp.bitMap;
  2544.     ri := Screen.viewPort.rasInfo;
  2545.  
  2546.     IF ci>0 THEN g.LoadRGB4(SYS.ADR(Screen.viewPort),Cols,ci) END;
  2547.   
  2548.     left := 0;
  2549.     top  := 0;
  2550.     width  := Screen.width;
  2551.     height := Screen.height;
  2552.  
  2553.   END;
  2554.  
  2555. (*------  Open Window:  ------*)
  2556.  
  2557.   IF win THEN
  2558.  
  2559.     IF pubscreenname="" THEN pub := I.LockPubScreen(NIL);
  2560.                         ELSE pub := I.LockPubScreen(pubscreenname); IF pub=NIL THEN pub := I.LockPubScreen(NIL) END END;
  2561.     IF pub # NIL THEN
  2562.  
  2563.       zoomBox[0] := left;
  2564.       zoomBox[1] := top;
  2565.       zoomBox[2] := 200;
  2566.       zoomBox[3] := pub.barHeight+1;
  2567.  
  2568.       Window := I.OpenWindowTagsA(NIL,
  2569.                                   I.waTitle,    SYS.ADR(MuchText),
  2570.                                   I.waLeft,     left,
  2571.                                   I.waTop,      top,
  2572.                                   I.waWidth,    width,
  2573.                                   I.waHeight,   height,
  2574.                                   I.waPubScreen,pub,
  2575.                                   I.waIDCMP,    MyIdcmp,
  2576.                                   I.waFlags,    LONGSET{I.windowDrag,I.windowClose,I.windowDepth,I.rmbTrap,I.activate,I.noCareRefresh},
  2577.                                   I.waZoom,     SYS.ADR(zoomBox),
  2578.                                   u.done);
  2579.       I.UnlockPubScreen(NIL,pub);
  2580.     END;
  2581.  
  2582.   ELSE
  2583.  
  2584.     Window := I.OpenWindowTagsA(NIL,
  2585.                                 I.waLeft,    0,
  2586.                                 I.waTop,     10,
  2587.                                 I.waWidth,   width,
  2588.                                 I.waHeight,  height-10,
  2589.                                 I.waCustomScreen,Screen,
  2590.                                 I.waIDCMP,   MyIdcmp,
  2591.                                 I.waFlags,   LONGSET{I.rmbTrap,I.activate,I.borderless,I.noCareRefresh,I.simpleRefresh,I.backDrop},
  2592.                                 u.done);
  2593.   END;
  2594.  
  2595.   IF Window=NIL THEN Error(LocStr(MSGCOW)^) END;
  2596.   initialheight := Window.height;
  2597.  
  2598.   IF win THEN
  2599.     rp := Window.rPort;
  2600.     left   := Window.borderLeft; top    := Window.borderTop;
  2601.     width  := Window.gzzWidth;   height := Window.gzzHeight;
  2602.     Scrollable := f;
  2603.  
  2604.     IF depth < rp.bitMap.depth THEN
  2605.       IF g.base.libNode.version >= 39 THEN g.SetMaxPen(rp,ASH(LONG(1),depth)-1)
  2606.                                       ELSE rp.mask := SHORTSET{0..depth-1}   END;
  2607.     END;
  2608.  
  2609.   END;
  2610.  
  2611. (*------  Open Font:  ------*)
  2612.  
  2613.   IF FontName # "" THEN
  2614.     MyAttr.name := SYS.ADR(FontName);
  2615.     MyAttr.ySize := FontSize;
  2616.     diskFontBase := e.OpenLibrary("diskfont.library",0);
  2617.     IF diskFontBase # NIL THEN MyFont := OpenDiskFont(MyAttr) END;
  2618.     IF (MyFont # NIL) & ~(g.proportional IN MyFont.flags) THEN
  2619.       OldFont := rp.font;
  2620.       g.SetFont(rp,MyFont)
  2621.     END;
  2622.   END;
  2623.  
  2624.   LOOP
  2625.     fontWidth  := rp.font.xSize;
  2626.     fontHeight := rp.font.ySize;
  2627.     IF (fontWidth<=80) & (fontHeight<=80) & (fontWidth>=4) & (fontHeight>=4) THEN EXIT END;
  2628.     MyAttr.name := SYS.ADR("topaz.font");
  2629.     MyAttr.ySize := 8;
  2630.     MyFont := g.OpenFont(MyAttr);
  2631.     IF MyFont=NIL THEN HALT(d.fail) END;
  2632.     IF OldFont=NIL THEN OldFont := rp.font END;
  2633.     g.SetFont(rp,MyFont);
  2634.   END;
  2635.   INC(fontHeight,spacing);               (* extra spacing *)
  2636.   fontBaseLine := rp.font.baseline;
  2637.  
  2638.   NumColumns := width DIV fontWidth;
  2639.   IF Scrollable THEN NumLines   := (height DIV 2) DIV fontHeight;
  2640.                 ELSE NumLines   := height DIV fontHeight; END;
  2641.   PageHeight := fontHeight*NumLines;
  2642.   height :=     PageHeight;
  2643.  
  2644.   (* ClearDisplay;*)
  2645.  
  2646.   IF Scrollable THEN
  2647.     Screen.height := height;
  2648.     I.OldMakeScreen(Screen);
  2649.     I.OldRethinkDisplay;
  2650.   ELSIF win THEN
  2651.     INC(top,(Window.gzzHeight-height) DIV 2);
  2652.   END;
  2653.  
  2654. (*------  Get KeyMap:  ------*)
  2655.  
  2656.   IF e.OpenDevice("console.device",-1,conreq,LONGSET{})#0 THEN HALT(d.fail) END;
  2657.   console := conreq.device;
  2658.   con.base := console;
  2659. (*ievent.nextEvent := NIL;
  2660.   ievent.qualifier := {};
  2661.   ievent.eventAddress := NIL; *)
  2662.   ievent.class := ie.rawkey;
  2663.  
  2664.   FOR i := 0 TO 3FH DO
  2665.     ievent.code := i;
  2666.     SYS.SETREG(0,con.RawKeyConvert(ievent,KeyMap[i],16,NIL));
  2667.   END;
  2668.  
  2669. (*------  Decrunch:  ------*)
  2670.  
  2671.   Decrunch;
  2672.  
  2673. (*------  Init & Add 2nd Task:  ------*)
  2674.  
  2675.   ShowTask.spLower := ShowStack;
  2676.   ShowTask.spUpper := SYS.VAL(e.APTR,SYS.VAL(LONGINT,ShowStack) + ShowStackSize);
  2677.   ShowTask.spReg   := ShowTask.spUpper;
  2678.   ShowTask.node.type := e.task;
  2679.   ShowTask.node.name := SYS.ADR("muchmore show task");
  2680.   ShowTask.node.pri  := Me.task.node.pri+1;
  2681.   (* $IF SmallData *)
  2682.   ShowTask.userData  := SYS.REG(13);           (* VarBase *)
  2683.   (* $END *)
  2684.  
  2685.   e.Forbid;
  2686.    e.AddTask(ShowTask,ShowProc,NIL);
  2687.    ShowTaskRunning := w;
  2688.   e.Permit;
  2689.  
  2690.   SYS.SETREG(0,e.Wait(mySig));
  2691.  
  2692.   IF ~showTaskOk THEN HALT(d.fail) END;
  2693.  
  2694. (*------  Main Load / Display Loop:  ------*)
  2695.  
  2696.   LOOP
  2697.     fg := 1; bg := 0; oldfg := fg; oldbg := bg; style := SHORTSET{};
  2698.     RQLen := -1; RQPos := -1;
  2699.     AnzLines := 1;
  2700.     LastLine := FirstLine;
  2701.     BottomLine := FirstLine;
  2702.     TopLine    := FirstLine;
  2703.     TextLength := 0;
  2704.     ReadLength := 0;
  2705.     FindLine   := NIL;
  2706.     FOR i := 0 TO 9 DO TextMarkers[i] := NIL END;
  2707.  
  2708.     FileLength := 0;
  2709.  
  2710.     IF ~stdin THEN
  2711.       MyLock := d.Lock(Name,d.sharedLock);
  2712.       IF MyLock # NIL THEN
  2713.         IF d.Examine(MyLock,FileInfo^) THEN FileLength := FileInfo.size END;
  2714.         d.UnLock(MyLock); MyLock := NIL;
  2715.         IF FileLength=0 THEN Error(LocStr(MSGEMPTY)^) END;
  2716.       END;
  2717.     END;
  2718.  
  2719.     (*------  Start displaying & Loading:  ------*)
  2720.  
  2721.     NewDisp := w;
  2722.     e.Signal(ShowTask,showSig);
  2723.  
  2724.     REPEAT
  2725.       LoadLine := GetTextLine();
  2726.       IF LoadLine=NIL THEN
  2727.         IF ~stdin THEN d.OldClose(MyFile) END;
  2728.         MyFile := NIL;
  2729.       ELSE
  2730.         LoadLine.prev := LastLine;
  2731.         LastLine.next := LoadLine;
  2732.         LastLine := LoadLine;
  2733.       END;
  2734.       IF SignalNewData THEN e.Signal(ShowTask,showSig) END;
  2735.     UNTIL (MyFile=NIL) OR Done OR NewText;
  2736.     IF SignalAllRead THEN e.Signal(ShowTask,showSig) END;
  2737.     REPEAT
  2738.       SYS.SETREG(0,e.Wait(mySig));
  2739.       IF print THEN
  2740.         in  := d.Open("NIL:",d.newFile);
  2741.         IF d.SystemTags(PStr,d.sysInput,    SYS.VAL(e.APTR,in),
  2742.                              d.sysOutput,   NIL,
  2743.                              d.sysAsynch,   d.DOSTRUE,
  2744.                              d.sysUserShell,d.DOSTRUE,
  2745.                              u.done)                   = -1 THEN
  2746.           d.OldClose(in);
  2747.         ELSE
  2748.           Decrunched := f; INC(meInt);
  2749.         END;
  2750.         in := NIL;
  2751.         print := f;
  2752.       END;
  2753.       IF save THEN
  2754.         in := d.Open(Name,d.oldFile);
  2755.         IF in=NIL THEN I.DisplayBeep(NIL) ELSE
  2756.           ol.New(buffer,savesize);
  2757.           SYS.SETREG(0,d.Seek(in,savefrom,0));
  2758.           IF d.Read(in,buffer^,savesize) # savesize THEN
  2759.             I.DisplayBeep(NIL);
  2760.             d.OldClose(in); in := NIL;
  2761.           ELSE
  2762.             d.OldClose(in); in := NIL;
  2763.             IF copy THEN
  2764.               iff := NIL;
  2765.               LOOP
  2766.                 IF ip.base=NIL THEN EXIT END;
  2767.                 iff := ip.AllocIFF();                               IF iff       =NIL THEN EXIT END;
  2768.                 iff.stream := SYS.VAL(LONGINT,ip.OpenClipboard(0)); IF iff.stream=NIL THEN EXIT END;
  2769.                 ip.InitIFFasClip (iff);
  2770.                 IF (ip.OpenIFF  (iff, ip.write) = 0) &
  2771.                    (ip.PushChunk(iff, SYS.VAL(LONGINT,"FTXT"), ip.idFORM, ip.sizeUnknown)=0) &
  2772.                    (ip.PushChunk(iff, 0, SYS.VAL(LONGINT,"CHRS"), ip.sizeUnknown)=0) &
  2773.                    (ip.WriteChunkBytes(iff,buffer^,savesize) = savesize) &
  2774.                    (ip.PopChunk (iff)=0) &
  2775.                    (ip.PopChunk (iff)=0) THEN
  2776.                 END;
  2777.                 EXIT;
  2778.               END;
  2779.               IF iff # NIL THEN
  2780.                 ip.CloseIFF(iff);
  2781.                 IF iff.stream#0 THEN ip.CloseClipboard (SYS.VAL(e.APTR,iff.stream)) END;
  2782.                 ip.FreeIFF (iff);
  2783.               END;
  2784.             ELSE
  2785.               out := d.Open(WriteName,d.oldFile);
  2786.               IF out=NIL THEN
  2787.                 out := d.Open(WriteName,d.newFile);
  2788.               ELSE
  2789.                 SYS.SETREG(0,d.Seek(out,0,d.end));
  2790.               END;
  2791.               IF out=NIL THEN I.DisplayBeep(NIL) ELSE
  2792.                 IF d.Write(out,buffer^,savesize)#savesize THEN I.DisplayBeep(NIL) END;
  2793.                 d.OldClose(out); out := NIL;
  2794.               END;
  2795.             END;
  2796.           END;
  2797.           DISPOSE(buffer);
  2798.         END;
  2799.         save := f;
  2800.       END;
  2801.       IF Done THEN EXIT END;
  2802.     UNTIL NewText;
  2803.     IF MyFile # NIL THEN
  2804.       IF ~stdin THEN d.OldClose(MyFile) END;
  2805.       MyFile := NIL
  2806.     END;
  2807.     IF Decrunched & d.DeleteFile(Name) THEN END;
  2808.     Decrunched := f;
  2809.     DisposeLines();
  2810.     FirstLine.next := NIL; NewText := f;
  2811.     Name := OldName;
  2812.     stdin := FALSE;
  2813.     REPEAT
  2814.       IF ~FileReq(Name) THEN HALT(d.ok) END;
  2815.       MyFile := d.Open(Name,d.oldFile);
  2816.     UNTIL MyFile # NIL;
  2817.     Decrunch;
  2818.   END;   (* LOOP *)
  2819.  
  2820. CLOSE
  2821.  
  2822.   IF OldFont     # NIL THEN g.SetFont(rp,OldFont)            END;
  2823.   IF Window      # NIL THEN Window.userPort.sigTask := Me    END;
  2824.   IF ShowTaskRunning   THEN e.RemTask(ShowTask)              END;
  2825.   IF console     # NIL THEN e.CloseDevice(conreq)            END;
  2826.   IF Window      # NIL THEN I.CloseWindow(Window)            END;
  2827.   IF Screen      # NIL THEN I.OldCloseScreen(Screen)         END;
  2828.   IF MyFont      # NIL THEN g.CloseFont(MyFont)              END;
  2829.   IF (MyFile#NIL) & ~stdin THEN d.OldClose(MyFile)           END;
  2830.   IF in          # NIL THEN d.OldClose(in)                   END;
  2831.   IF out         # NIL THEN d.OldClose(out)                  END;
  2832.   IF Decrunched        THEN SYS.SETREG(0,d.DeleteFile(Name)) END;
  2833.   IF xpk         # NIL THEN e.CloseLibrary(xpk)              END;
  2834.   IF asl         # NIL THEN e.CloseLibrary(asl)              END;
  2835.   IF diskFontBase# NIL THEN e.CloseLibrary(diskFontBase)     END;
  2836.   IF iconBase    # NIL THEN e.CloseLibrary(iconBase)         END;
  2837.   IF mySigBit >= 0     THEN e.FreeSignal(mySigBit)           END;
  2838.   IF catalog     # NIL THEN loc.CloseCatalog(catalog);       END;
  2839.   IF taskpri # oldpri  THEN oldpri := e.SetTaskPri(Me,oldpri)END;
  2840.   OldDir := d.CurrentDir(OldDir);
  2841.  
  2842. END MuchMore.
  2843.  
  2844.